Help Wanted

Dumb peice of crap code... – en972

en972

Member

Posts: 562
From: NOT TELLING!
Registered: 08-27-2004
I need help on this code....please...mommy....


#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
char age;
char result;

cout<< "How old are you?" <<endl;
cin.ignore();

if (age= '30+')
result = cout<< "HOLY CRAP YOUR OLD!" <<endl;
if (age= '30-')
result = cout<< "Dude...your young..." <<endl;
system("PAUSE");
return 0;
}

------------------
Hard work often pays off in time, but lazieness always pays off now.

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 . . .

------------------
"The very idea of freedom presupposes some objective moral law which overarches rulers and ruled alike." -- C. S. Lewis (1898 - 1963), "The Poison of Subjectivism" (from Christian Reflections; p. 108)

Switch Mayhem now available! Get it here
Codename: Roler - hoping to get more done over the holidays . . .

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.

------------------
Kevin Ryan
Marble Blast
Minigolf Blast

en972

Member

Posts: 562
From: NOT TELLING!
Registered: 08-27-2004
quote:

dont mean to sound insulting

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....

------------------
Hard work often pays off in time, but lazieness always pays off now.

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.

------------------
"The very idea of freedom presupposes some objective moral law which overarches rulers and ruled alike." -- C. S. Lewis (1898 - 1963), "The Poison of Subjectivism" (from Christian Reflections; p. 108)

Switch Mayhem now available! Get it here
Codename: Roler - hoping to get more done over the holidays . . .

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>
#include <stdlib.h>
#include <string.h>
#include <time.h>

using namespace std;

int main()
{

string response[2] = {

"WOW YOUR OLD!",
"Dang your young.."};

string number;

cout<< "How old are you?" <<endl;
cin>> number;
system("PAUSE");
return 0;
}

------------------
Keep the holy day sacred.......halllllllukan

[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>
using namespace std;

void main( ) {
int age;

cout << "How old are you?" << endl;
cin >> age;

if (age >= 30)
cout << "WOW YOUR OLD!" << endl;
else
cout << "Dang your young.." << endl;

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?

------------------
Keep the holy day sacred.......halllllllukan

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
}

------------------
Vita sine Ieso est mors.
Life without Jesus is death.
Enter The Circle

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

------------------
Keep the holy day sacred.......halllllllukan

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

------------------
Keep the holy day sacred.......halllllllukan