Jump to content

C++ madlib stuck. Help! (Begginer)

Icycookies

I think i am doing string wrong? I tried compiling it but no dice just a whole bunch of errors.

//Madlib Assignment#include <iostream>#include <string>using namespace std;void measuringstick(int y,char x);{for(int i=0;i<y;i++);cout<<x;}int main();{        string color, superlative , adjective , bodypart , bodypart1 , noun , animal , adjective1 , adjective2 , adjective3 ;       cout << " Please enter a Color: \n";    cin >> color;    cout << "Please enter a Superlative(ENDING IS EST): \n";    cin >> superlative;    cout << "Please enter a Adjective:  \n";    cin >> adjective;    cout << "Please enter a Bodypart  \n";    cin >> bodypart;    cout << "Please enter a Bodypart  \n";    cin >> bodypart1;    cout << "Please eneter a  Noun \n";    cin >> noun;    cout << "Please enter a animal \n";    cin >> animal;    cout << "Please enter a Adjective:  \n";    cin >> adjective1;    cout << "Please enter a Adjective:  \n";    cin >> adjective2;    cout << "Please enter a Adjective:  \n";    cin >> adjective3;        string measuringStick (80, '-');    cout << "The " << color << " Dragon is the " << superlative << " Dragon of all.  It has" << adjective << bodypart << ", and a" << bodypart1 << "shaped like a " << noun;    cout << ".\nIt loves to eat" << animal << ", although it will feast on nearly anything. It is " << adjective1 << " and " << adjective2 << ". You must be" << adjective3 <<" around it, or you may end up as it`s meal!";    string measuringStick (80, '-');        return 0;}
Link to comment
Share on other sites

Link to post
Share on other sites

you can replace measuringStick  function with a for loop

for(int i=0;i<80;i++){cout<<'-';}
Link to comment
Share on other sites

Link to post
Share on other sites

Haha thank you i barely noticed that. Now i am just problems with the measuring stick.

Link to comment
Share on other sites

Link to post
Share on other sites

Have you learned about functions yet? If not, you can make a simple for loop:

No. The professor wants the measuring stick.

Link to comment
Share on other sites

Link to post
Share on other sites

No. The professor wants the measuring stick.

void measuringstick(int y,char x){for(int i=0;i<y;i++)cout<<x;}

This should work

 

Edit you should place the function before int main()

Link to comment
Share on other sites

Link to post
Share on other sites

void measuringstick(int y,char x){for(int i=0;i<y;i++)cout<<x;}

This should work

 

Edit you should place the function before int main()

 

Okay i put it in there. However now i only get this error

 

Madlibs.cpp:8:1: error: expected unqualified-id before ‘{’ token

 {

 ^

Madlibs.cpp:17:1: error: expected unqualified-id before ‘{’ token

 {

Link to comment
Share on other sites

Link to post
Share on other sites

Okay i put in there. However now i only get this error

 

Madlibs.cpp:8:1: error: expected unqualified-id before ‘{’ token

 {

 ^

Madlibs.cpp:17:1: error: expected unqualified-id before ‘{’ token

 {

 

can you post the code ?

 

edit I just saw that you updated it

Link to comment
Share on other sites

Link to post
Share on other sites

#include <iostream>#include <string>using namespace std;void measuringStick(int y,char x){for(int i=0;i<y;i++)cout<<x;}int main(){    string color, superlative , adjective , bodypart , bodypart1 , noun , animal , adjective1 , adjective2 , adjective3 ;    cout << " Please enter a Color: \n";    cin >> color;    cout << "Please enter a Superlative(ENDING IS EST): \n";    cin >> superlative;    cout << "Please enter a Adjective:  \n";    cin >> adjective;    cout << "Please enter a Bodypart  \n";    cin >> bodypart;    cout << "Please enter a Bodypart  \n";    cin >> bodypart1;    cout << "Please eneter a  Noun \n";    cin >> noun;    cout << "Please enter a animal \n";    cin >> animal;    cout << "Please enter a Adjective:  \n";    cin >> adjective1;    cout << "Please enter a Adjective:  \n";    cin >> adjective2;    cout << "Please enter a Adjective:  \n";    cin >> adjective3;    measuringStick (80,'-');    cout << "The " << color << " Dragon is the " << superlative << " Dragon of all.  It has" << adjective << bodypart << ", and a" << bodypart1 << "shaped like a " << noun;    cout << ".\nIt loves to eat" << animal << ", although it will feast on nearly anything. It is " << adjective1 << " and " << adjective2 << ". You must be" << adjective3 <<" around it, or you may end up as it`s meal!";    measuringStick (80, '-');    return 0;}

You shouldn't put " ; " after int main or after void measuringStick(int y,char x) and not after for loop also when you recall a function you don't redefine it string measuringStick(80,'-')

Link to comment
Share on other sites

Link to post
Share on other sites

Can you explain the void  part if you do not mind? Okay running fine now thank you for the help. Now just have to fix some minor things in the outputs.

Link to comment
Share on other sites

Link to post
Share on other sites

I suck at explaining but I'll try my best 

 

actually I don't know what to explain so I'll tell you what was wrong with your original code

 

you were trying to call measuringStick function which wasn't exist 

 

 
void measuringstick(int y,char x);  \\ void function mean that is doesn't return a number or something like that.... \\(int y,char x) those are the 2 parameter (variables) that you are going to give it to the function to process 
{
for(int i=0;i<y;i++);               \\ you already inserted y as 80 and x as  '-' so the loop work for 80 times each time '-' will be printed
cout<<x;
}
 
------------------------------
 
this an example of a function which return sum of 2 integers 
 
int Sumof2(int x,int y)
{
int sum;
sum=x+y;
return sum;
}
 
 
so when you write it inside the main function 
 
int main()
{
int a;
a=Sumof(4,2);
cout<<Sumof2(5,9)<<a;
}
 
the OutPut will be 7 and 14
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×