Question

In: Computer Science

I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as...

I need assistance on what I am doing wrong, I've been trying to declare "getRandomLetter" as a scope, but haven't found how to all day. It's been about 3+ hours and I still have nothing. Please help fix these and let me know what I am doing wrong (There may be more simple ways of coding all this, but I just need help fixing the errors with current code, thank you). I am trying to have buildAcronym() hold the position of going from A-Z , & as well as getRandomLetter() choose a letter from A-Z using the ASCII character set. This is a bit of the prompt where it asks to set these up. If I am off, I do apologize.

Define and overload two void-typed functions named buildAcronym that assign a (pseudo)-random uppercase letter to two (2) or three (3) character parameters, depending on the version called. Each character in an acronym must be a unique uppercase letter. Two arguments (or three, depending on the version called) will be assigned a random character literal, which can then be printed out in main.

These are my errors.

Acronyms.cpp: In function 'void buildAcronym(char, char, char)':
Acronyms.cpp:13:35: error: 'getRandomLetter' was not declared in this scope
getRandomLetter(a , b , c)
^
Acronyms.cpp: In function 'void buildAcronym(char, char)':
Acronyms.cpp:25:24: error: 'getRandomLetter' was not declared in this scope
getRandomLetter(a,b)
^
Acronyms.cpp: In function 'int main()':
Acronyms.cpp:50:39: error: 'getRandomLetter' was not declared in this scope
cout << getRandomLetter(a,b) ;
^
Acronyms.cpp:56:42: error: 'getRandomletter' was not declared in this scope
cout << getRandomletter(a,b,c);
^
Acronyms.cpp:60:9: error: expected ';' before '{' token
{
^
Acronyms.cpp:67:1: error: expected 'while' at end of input
}
^
Acronyms.cpp:67:1: error: expected '(' at end of input
Acronyms.cpp:67:1: error: expected primary-expression at end of input
Acronyms.cpp:67:1: error: expected ')' at end of input
Acronyms.cpp:67:1: error: expected ';' at end of input
Acronyms.cpp:67:1: error: expected '}' at end of input

------------------------------------------------------------------------------------------------------------------------------------

--

--------------------------------------

(there are 3 lines above include Name: Date: Filename: apologies that it is missing)

#include
using namespace std;


void buildAcronym(char a ,char b , char c)
{
if('A'<= b && 'A' <= b && 'A' <= c && a <= 'Z' && b <= 'Z' && c <= 'Z')
{
getRandomLetter(a , b , c)
{
cout << a + rand() % 65 + 90 << "." ;
cout << b + rand() % 65 + 90 << "." ;
cout << c + rand() % 65 + 90 << "." ;
}
}
return ;
}

void buildAcronym(char a , char b)
{
getRandomLetter(a,b)
{
cout << a + rand() % 65 + 90 << "." ;
cout << b + rand() % 65 + 90 << "." ;
}

return ;
}

int main()
{
char a , b , c ;
int choice ;
do
{
cout << "Press 1 for a two letter acronym, and 2 for a three letter acronym. " ;
cin >> choice ;
switch(choice)
{
case 1 :

if (choice == 1)
{

cout << getRandomLetter(a,b) ;
break ;
}
case 2 :
if (choice == 2)
{
cout << getRandomletter(a,b,c);
break;
}
else (choice != 1 && choice != 2)
{
cout << "Press 1 for a two letter acronym, and 2 for a three letter acronym. ";
}
}while(choice!=1 && choice != 2);

return 0;
}

Solutions

Expert Solution

Here is your updated code, there were lots of redundant lines that was simplified. The entire program can be rewritten in a few lines but since you wanted to modify your code and make changes, I followed that only.

Here is the code with screenshot. Hope this is what you were looking for, If you get stuck let me know.

=========================================================================

#include <iostream>
#include<cstdlib> // for generating random number
#include<string>
using namespace std;

// returns a random letter from A to Z
char getRandomLetter(){
   int range = 'Z'-'A';
   return 'A' + rand()%range;
}
// overloaded takes 2 arguments
string buildAcronym(char firstLetter, char secondLetter)
{
   return string(1,firstLetter)+string(1,secondLetter);
}

// overloaded takes 3 arguments
string buildAcronym(char firstLetter, char secondLetter, char thirdLetter)
{
   return string(1,firstLetter)+string(1,secondLetter) +string(1,thirdLetter);
}

char getUniqueLetter(char used_one, char used_two){
   char a;
   do{
       a = getRandomLetter();
   }while(a==used_one || a==used_two);
   return a;
}


int main()
{
char a , b , c ;
int choice ;
cout << "1 for a two letter acronym\n2 for a three letter acronym\n3 Quit\n\n";
do
{
cout<<"Enter choice: " ;
cin >> choice ;
switch(choice)
{
case 1 :
   a = getUniqueLetter(b,c);
   b=getUniqueLetter(a,c);
   cout<<buildAcronym(a,b)<<endl;
  
break ;

case 2 :
   a = getUniqueLetter(b,c);
   b = getUniqueLetter(a,c);
   c = getUniqueLetter(a,b);
   cout<<buildAcronym(a,b,c)<<endl;
break;
case 3:break;

default:
   cout<<"Press 1 or 2 or 3 only.\n Please try again."<<endl;


}

}while(choice!=3);
return 0;
}

======================================================================


Related Solutions

I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point for the following titration 0.20M HCl versus 0.20M methylamine (CH3NH2). The Ka of methylammonium is 2.3x10^-11. First I have to divide .20M methylamine by 2 (Why?) to get .10M Then, I set up the equilibrium: (2.3 x 10^-11) = x^2 / .10M Since the ka is SO small, I just multiplied .10 with (2.3 x 10^-11) to get 2.3x10^-12, which is wrong. Why is...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I am doing a project on cancerous cell types and I've already identified 20 kinds, the...
I am doing a project on cancerous cell types and I've already identified 20 kinds, the tissues they effect, and the exact disease they cause. There are multiple other steps to the project that I am struggling with. This involves finding biochemicals (such as lipids, proteins, etc) associated with specific cancer cell types, the metabolic pathways they effect, membrane proteins (such as growth factors) and membrane protein transporters associated with the cancer cell type. Could someone give me an idea...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs...
Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs an I of a size entered by the user. Prompt the user for a size. If -1 is entered, quit the program. If an even number or a number smaller than 3 is entered, prompt the user again. Then output a shape of # characters that represent an I. Repeat the program until -1 is entered. What I have so far: #include <iostream> #include...
I am trying to understand a few injection molding calculations. I will appreciate your assistance. How...
I am trying to understand a few injection molding calculations. I will appreciate your assistance. How do I calculate part weight for plastic injection molding? Is it mass * density or volume * density? My part is 29.126 grams and I am using  Polypropylene (PP) which has a density of 0.899 g/cm3 . Therefore : 29.126 * 0.899= 26.184 grams To convert to ounce: 26.184* 1/28.3495=0.9236 ounce Is the above correct? How do I calculate shot weight?  Please explain clearly and give...
I am trying to understand a few injection molding calculations. I will appreciate your assistance. How...
I am trying to understand a few injection molding calculations. I will appreciate your assistance. How do I calculate part weight for plastic injection molding? Is it mass * density or volume * density? My part is 29.126 grams and I am using  Polypropylene (PP) which has a density of 0.899 g/cm3 . Therefore : 29.126 * 0.899= 26.184 grams To convert to ounce: 26.184* 1/28.3495=0.9236 ounce Is the above correct? How do I calculate shot weight?  Please explain clearly and give...
Hello, I am in need of some assistance in interpreting the data for the two variables...
Hello, I am in need of some assistance in interpreting the data for the two variables I did in a t-test for in Excel. Variable 1 is Relationship with Direct Supervisor and Variable 2 is the Workplace Happiness Rating. I am supposed to write a 125- to 175-word summary of my interpretation of the results of the t test. t-Test: Two-Sample Assuming Equal Variances Variable 1 Variable 2 Mean 2.5 7.4 Variance 1.030612245 2 Observations 50 50 Pooled Variance 1.515306122...
What am I doing wrong in my bootstrap code for R? x<-c(30, 37, 36, 43, 42,...
What am I doing wrong in my bootstrap code for R? x<-c(30, 37, 36, 43, 42, 43, 43, 46, 41, 42) n = 10 x=pnorm(n,mean=40.3,sd=4.6) mu_0=40.3 s.mean=mean(x) s.sd=sd(x);s.sd [1] NA t.sample=(s.mean-mu_0)/(s.sd/sqrt(n)) B=10000 t=c() count.less=0 count.more=0 for(j in 1:B) + { b.smpl = x[sample(1:n, size = n,replace=TRUE)] + ybar.bs = mean(b.smpl) + sd.bs = sd(b.smpl) + t[j] = (ybar.bs - s.mean)/(sd.bs/sqrt(n)) + if(t[j]>=t.sample){ count.more=count.more+1} + if(t[j]<=t.sample){ count.less=count.less+1} + } Error in if (t[j] >= t.sample) { : missing value where TRUE/FALSE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT