Welcome to Dream.In.Code
Getting C++ Help is Easy!

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!




instructor reccommended this site for assistance

 
Reply to this topicStart new topic

instructor reccommended this site for assistance

wheelies
post 4 Sep, 2008 - 10:56 AM
Post #1


New D.I.C Head

*
Joined: 3 Sep, 2008
Posts: 10

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
*/

#include<iostream>
using namespace std;

int main()
{

//declare variables

float firstNameofinstructor, yourName, aFood, aNumberbetween100-120, anAdjective, aColor, anAnimal;

//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";

system("pause");

return 0;
}

Mod edit: Please code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM

Go to the top of the page

MorphiusFaydal
post 4 Sep, 2008 - 11:08 AM
Post #2


D.I.C Lover

Group Icon
Joined: 12 May, 2005
Posts: 1,086



Thanked 8 times

Expert In: Hardware, Networking

My Contributions


Your variable name "aNumberbetween100-120" is invalid. Change it. smile.gif "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? smile.gif

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? smile.gif

And... code.gif

This post has been edited by MorphiusFaydal: 4 Sep, 2008 - 11:15 AM
User is offlineProfile CardPM

Go to the top of the page

wheelies
post 4 Sep, 2008 - 11:45 AM
Post #3


New D.I.C Head

*
Joined: 3 Sep, 2008
Posts: 10

QUOTE(MorphiusFaydal @ 4 Sep, 2008 - 12:08 PM) *

Your variable name "aNumberbetween100-120" is invalid. Change it. smile.gif "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? smile.gif

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? smile.gif

And... code.gif



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
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 4 Sep, 2008 - 11:52 AM
Post #4


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


Can you post your updated code?
User is offlineProfile CardPM

Go to the top of the page

wheelies
post 4 Sep, 2008 - 12:07 PM
Post #5


New D.I.C Head

*
Joined: 3 Sep, 2008
Posts: 10

QUOTE(Amadeus @ 4 Sep, 2008 - 12:52 PM) *

Can you post your updated code?

cpp
/*rob klibenski
created september 03, 2008
modified september 03, 2008
description--mad-lib problem #14 page 108
*/

#include<iostream>
#include<string>
using namespace std;

int main()
{

//declare variables

string name; "firstNameofinstructor, yourName, aFood, aNumberbetween100120,anAdjective, aColor, anAnimal";

//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
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 4 Sep, 2008 - 12:20 PM
Post #6


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,441



Thanked 94 times

Dream Kudos: 2625

Expert In: ruling the world.

My Contributions


What I meant was something like this:
[code]Paste your in between these tags[/code]
User is online!Profile CardPM

Go to the top of the page

wheelies
post 4 Sep, 2008 - 01:04 PM
Post #7


New D.I.C Head

*
Joined: 3 Sep, 2008
Posts: 10

QUOTE(gabehabe @ 4 Sep, 2008 - 01:20 PM) *

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
User is offlineProfile CardPM

Go to the top of the page

MorphiusFaydal
post 4 Sep, 2008 - 01:13 PM
Post #8


D.I.C Lover

Group Icon
Joined: 12 May, 2005
Posts: 1,086



Thanked 8 times

Expert In: Hardware, Networking

My Contributions


QUOTE(wheelies @ 4 Sep, 2008 - 04:04 PM) *

QUOTE(gabehabe @ 4 Sep, 2008 - 01:20 PM) *

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. wink2.gif ) 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. smile.gif

This post has been edited by MorphiusFaydal: 4 Sep, 2008 - 01:14 PM
User is offlineProfile CardPM

Go to the top of the page

jwwicks
post 4 Sep, 2008 - 01:16 PM
Post #9


D.I.C Head

Group Icon
Joined: 31 Jul, 2008
Posts: 59



Thanked 6 times

Dream Kudos: 200
My Contributions


Hello wheelies,

QUOTE

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


Change the type declarations to the following...
cpp


string firstNameofinstructor, yourName, aFood, anAdjective, aColor, anAnimal;
float aNumberbetween100120;



JW
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 06:34AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month