Thursday, July 30, 2009

Help with program?

I'm really new at C++ and I was trying to write a program that insults people. However, I am stuck at the gender part. How do I make it so that if someone inputs a, it will output the response for that input? I tried using if statements, but it doesn't work. What do I need to add to the code? Thanks in advance.








#include %26lt;iostream%26gt;


#include %26lt;iomanip%26gt;





using namespace std;





int main()


{


char gender[6];


char fname[20];


char stname[20];


char school[20];


char city[20];


char state[20];


int age;








cout %26lt;%26lt; "1. What is your first name?" %26lt;%26lt;endl;


cin %26gt;%26gt; fname;


cout %26lt;%26lt;endl;


system("cls");


cout %26lt;%26lt; fname %26lt;%26lt; "? What kind of a cheap name is that? Where'd you find that name anyways? On the side of a dump?" %26lt;%26lt;endl;


cout %26lt;%26lt;endl;


cout %26lt;%26lt; "2. What's your gender?" %26lt;%26lt;endl;


cout %26lt;%26lt; "a. Female b. Male c. Other" %26lt;%26lt;endl;


cin %26gt;%26gt; gender;


system("cls");


if (char gender='a')


{


cout %26lt;%26lt; "You're a female!? WOW, I never would've guessed. I could've sworn you were a dude from your name."%26lt;%26lt;endl;


}


if(char gender='b')


{


cout %26lt;%26lt; "I didn't know you were a male. Your name sounds very feminine. No offense of course, but you should consider legally changing your name soon."%26lt;%26lt;endl;


}


if(char gender='c')


{


cout %26lt;%26lt; "I don't think I want to hear any more from you..." %26lt;%26lt;endl;


}





cout %26lt;%26lt; "3. What state do you live in?" %26lt;%26lt;endl;


cin %26gt;%26gt; state;


system("cls");


cout %26lt;%26lt; "I used to live in " %26lt;%26lt; state %26lt;%26lt;". It was full of losers."%26lt;%26lt;endl;


cout%26lt;%26lt;endl;


cout %26lt;%26lt; "4. Soo, what is the name of your street?(Please don't add other unnecessary crap like St, Dr, or Rd; no one cares)"%26lt;%26lt;endl;


cin %26gt;%26gt; stname;


system("cls");


cout %26lt;%26lt; stname %26lt;%26lt; ". Hmm...I believe that's the strangest street name I've ever heard. Where did you say you lived? " %26lt;%26lt; state %26lt;%26lt; "? Are you sure it's not Mars?"%26lt;%26lt;endl;


cout %26lt;%26lt;endl;


cout %26lt;%26lt; "How old are you?" %26lt;%26lt;endl;


cin %26gt;%26gt; age;


system("cls");


if(age%26lt;=15)


{


cout %26lt;%26lt; "You are really young! That must mean you're dumb" %26lt;%26lt;endl;


}


else if(age%26gt;15,age%26lt;18)


{


cout %26lt;%26lt; "You're not old yet, but you're on your way. You'll be decrepit soon." %26lt;%26lt;endl;


}


else{


cout %26lt;%26lt; "You're kidding me? I'm surprised you're still alive. Being old isn't that bad though. You get to go into retirement and have weird people take care of you!" %26lt;%26lt;endl;


}





system("PAUSE");


return 0;


}

Help with program?
I write lite sample:


int main()


{


char gender; // notice i don't use array


cin%26gt;%26gt;gender;


if(gender=='a') // don't need to use char keyword and notice to ==


cout%26lt;%26lt;"female";


if(gender=='b')


cout%26lt;%26lt;"male";


else cout%26lt;%26lt;"huh?";


system("pause");


return 0;


}


for more info about operators in c++ visit:


http://www.cplusplus.com/doc/tutorial/op...


++++++++++


You're welcom but in age segment you must write:


else if(age%26gt;15 %26amp;%26amp; age%26lt;18)


Good programing :)
Reply:Try if (char gender[0] = 'a') {


. . .


}

snow of june

No comments:

Post a Comment