en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
I need help on this code....please...mommy....
using namespace std; int main(void) cout<< "How old are you?" <<endl; if (age= '30+') ------------------ |
CobraA1![]() Member Posts: 926 From: MN Registered: 02-19-2001 |
Um, heh, yikes. You'll want to use an int datatype for the age. In any case, that's not the proper way to compare strings anyways. And get rid of result - it's not doing anything. You can't use it that way with cout anyways. And you don't want cin.ignore(), you want cin >> age And, geez, umm, don't want to sound insulting or anything, but spend another week reading your programming book . . . ------------------ Switch Mayhem now available! Get it here |
kevryan Member Posts: 37 From: Shaver Lake, CA Registered: 07-20-2001 |
To aim you in the right direction... You are going to want an int version of age in addition to the input char string. Look up what 'atoi()' does. Find out what the difference is between '= and '=='. Now check what '>=' and '<' do. ------------------ |
en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
quote: its okay, i'm kinda new...and i dont use a book. I'm really not as bad a programmer as i seem...i just didn't put much effort into that.... ------------------ |
CobraA1![]() Member Posts: 926 From: MN Registered: 02-19-2001 |
Ok. Well, stop by the library, see if they have any programming books. May also want to buy a book. I personally prefer Deitel & Deitel books. ------------------ Switch Mayhem now available! Get it here |
en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
ok. I'll get one. heres my new code...I dont get any errors, but it still doesnt work #include <iostream> int main() [This message has been edited by en972 (edited February 01, 2005).] |
HeardTheWord![]() Member Posts: 224 From: Des Moines, IA Registered: 08-16-2004 |
You are on the right track. Here is code that does what you want. Try and play with it to see how it works. Getting errors is a good thing (trust me). The more mistakes you make the more you learn! #include <iostream> void main( ) { cout << "How old are you?" << endl; if (age >= 30) system("PAUSE"); It helps to get something that works and then make it so it doesn't work and figure out why. Examples from any book are a great place to start. Don't hesitate to ask more questions C++ is difficult and you seem to be on the right track. |
en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
wow, thanks alot dude. Thats exactly what i was looking for. i do have another question though. Sometimes I get an error that says [Warning] no newline at end of file. It doesn't affect my code, but what does it mean? ------------------ |
mellonamin![]() Member Posts: 119 From: Maryville, TN, United States Registered: 11-16-2004 |
It means exactly what it says...no newline at the end of the file... int main() { //code //newline } ------------------ |
HeardTheWord![]() Member Posts: 224 From: Des Moines, IA Registered: 08-16-2004 |
What compiler are you using? Dev-C++? |
en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
yeah, Dev-Cpp ------------------ |
HeardTheWord![]() Member Posts: 224 From: Des Moines, IA Registered: 08-16-2004 |
HA. I figured it out. Just downloaded Dev-C++. Put an extra line at the end of the file. Must be something Dev-C++ requires. I guess you need to change the void main() to int main() as well... [This message has been edited by HeardTheWord (edited February 01, 2005).] |
en972![]() Member Posts: 562 From: NOT TELLING! Registered: 08-27-2004 |
Got it, needed to change void to int ------------------ |