Join 132,679 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,197 people online right now. Registration is fast and FREE... Join Now!
Hello, My name is Rob. Iam brand new to the world of c++. I have a total of three classes under my belt. I so far have done the "hello world" and "Testing 1 2 3" codes. I have been given the assignment of a mad-lib and am having troubles. I think I am getting close but not sure. I know my variables are not defined correctly because I get many errors saying so. Any suggestions are much appreciated. This is driving me crazy and my instructor is not available to help me until monday. Below is what I have so far. How far off am I? Thanks in advance rob
cpp
/*rob klibenski created september 03, 2008 modified september 03, 2008 description--mad-lib problem #14 page 108 */
//displayed to screen cout<<"This is a game of mad-lib.endl";
cout<<"Please answer all of the questions and press enter.endl";
cout<<"please enter the first name of your instructor.endl"; cin>>firstNameofyourinstructor>>;
cout<<"Please enter your name.endl"; cin>>yourName>>;
cout<<"please enter the name of a food.endl"; cin>>aFood>>;
cout<<"please choose a number between 100-120.endl"; cin>>aNumberbetween100-120>>;
cout<<"Please enter an adjective.endl"; cin>>anAdjective>>;
cout<<"Please enter a color.endl"; cin>>aColor>>;
cout<<"Please enter the name of an animal.endl"; cin>>anAnimal>>;
cout<<"Dear"<<firstNameofinstructor<<endl; cout<<"I am sorry I am unable to turn in my homework at this time.endl"; cout<<"First I ate a rotton"<<aFood<<"which made me turn"<<aColor<<"and become extremely ill.endl" cout<<"I came down with a fever of"<<aNumberbetween 100-120<<"endl" cout<<"Next my"<<anAdjective<<"pet"<<an Animal<<"must have smelled the remains of the"<<aFood<<"on my homework,endl" cout<<"because he ate it. I am currently rewriting my homework and hope you will accept it late.endl"; cout<<"sincerely"<<yourName<<"endl";
Your variable name "aNumberbetween100-120" is invalid. Change it. "aNumberbetween100120" would work. Personally I would choose a shorter, easier to remember and easier to type variable name.
And. Text can not be stored in a "float" datatype, which stores only numbers. As you're using C++, you can include the string header and use datatype "string" for all text. Example:
cpp
#include <iostream> #include <string> using namespace std;
int main() { string name; int age;
cout << "What is your name? "; cin >> name;
cout << "How old are you? "; cin >> age;
cout << "You are " << name << ", and you are " << age << " years old!" << endl;
return 0; }
See?
Also, all your "endl" are in the wrong spot. Proper usage is thus:
cpp
void showSomeText() { cout << "Here's a line." << endl; cout << "Note the postion of my endline." << endl; }
That work?
And...
This post has been edited by MorphiusFaydal: 4 Sep, 2008 - 11:15 AM
Your variable name "aNumberbetween100-120" is invalid. Change it. "aNumberbetween100120" would work. Personally I would choose a shorter, easier to remember and easier to type variable name.
And. Text can not be stored in a "float" datatype, which stores only numbers. As you're using C++, you can include the string header and use datatype "string" for all text. Example:
cpp
#include <iostream> #include <string> using namespace std;
int main() { string name; int age;
cout << "What is your name? "; cin >> name;
cout << "How old are you? "; cin >> age;
cout << "You are " << name << ", and you are " << age << " years old!" << endl;
return 0; }
See?
Also, all your "endl" are in the wrong spot. Proper usage is thus:
cpp
void showSomeText() { cout << "Here's a line." << endl; cout << "Note the postion of my endline." << endl; }
That work?
And...
Thankyou\. I made all the changes you suggested but am still getting many errors regarding my variables. "Undeclared identifier: error c2065" any other suggestions? thanks rob
//displayed to screen cout<<"This is a game of mad-lib."<<endl;
cout<<"Please answer each question and then press enter."<<endl;
cout<<"please enter the first name of your instructor."<<endl; cin>>firstNameofinstructor;
cout<<"Please enter your name."<<endl; cin>>yourName;
cout<<"please enter the name of a food."<<endl; cin>>aFood;
cout<<"please choose a number between 100-120."<<endl; cin>>aNumberbetween100120;
cout<<"Please enter an adjective."<<endl; cin>>anAdjective;
cout<<"Please enter a color."<<endl; cin>>aColor;
cout<<"Please enter the name of an animal."<<endl; cin>>anAnimal;
cout<<"Dear"<<firstNameofinstructor<<endl; cout<<"I am sorry I am unable to turn in my homework at this time."<<endl; cout<<"First I ate a rotton"<<aFood<<"which made me turn"<<aColor<<"and become extremely ill."<<endl; cout<<"I came down with a fever of"<<aNumberbetween100120<<endl; cout<<"Next my"<<anAdjective<<"pet"<<anAnimal<<"must have smelled the remains of the"<<aFood<<"on my homework"<<endl; cout<<"because he ate it. I am currently rewriting my homework and hope you will accept it late.";endl; cout<<"sincerely"<<yourName<<endl;
system("pause");
return 0; }
I have the errors narrowed down to 15 from 63. All errors have the same code "undeclared indetifier errorc2065". Also, i am not sure what you all mean be paste code between
CODE
-
. If i am not doing that could you tell me how. I know my variables are lengthy names, but unti I get better at this I am going to keep them big so i can easier identify them thanks
What I meant was something like this: [code]Paste your in between these tags[/code]
Thank you all so much. Thats all it took was a little guidance. The program now runs and works well. I had to identify each variable with a string instead of all variables under one string. This is a great and very useful forum. You guys know your stuff. I am sure you will be hearing more from me. Thanks again. ron k
What I meant was something like this: [code]Paste your in between these tags[/code]
Thank you all so much. Thats all it took was a little guidance. The program now runs and works well. I had to identify each variable with a string instead of all variables under one string. This is a great and very useful forum. You guys know your stuff. I am sure you will be hearing more from me. Thanks again. ron k
Yeah, your line string name; "firstNameofinstructor, yourName, aFood, aNumberbetween100120,anAdjective, aColor, anAnimal"; should have been string name, Instructor, Food, Number, Adjective, Colour, Animal;. (I changed the variable names cuz I'm lazy and didn't want to type them. ) You declare a whole bunch of strings the same way your declare a whole bunch of floats or ints or any other variable type.... One after another, comma separated.
And if you wanted to be *really* correct, you'd spin the 'number' variable off into an int or float, unless you want to be able to type "three" or "two hundred nineteen" rather than just use "3" or "219" all the time.
This post has been edited by MorphiusFaydal: 4 Sep, 2008 - 01:14 PM
I have the errors narrowed down to 15 from 63. All errors have the same code "undeclared indetifier errorc2065". Also, i am not sure what you all mean be paste code between . If i am not doing that could you tell me how. I know my variables are lengthy names, but unti I get better at this I am going to keep them big so i can easier identify them thanks