Saturday 24 September 2011

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; %26quot;1. What is your first name?%26quot; %26lt;%26lt;endl;

cin %26gt;%26gt; fname;

cout %26lt;%26lt;endl;

system(%26quot;cls%26quot;);

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

cout %26lt;%26lt;endl;

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

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

cin %26gt;%26gt; gender;

system(%26quot;cls%26quot;);

if (char gender='a')

{

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

}

if(char gender='b')

{

cout %26lt;%26lt; %26quot;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.%26quot;%26lt;%26lt;endl;

}

if(char gender='c')

{

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

}



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

cin %26gt;%26gt; state;

system(%26quot;cls%26quot;);

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

cout%26lt;%26lt;endl;

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

cin %26gt;%26gt; stname;

system(%26quot;cls%26quot;);

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

cout %26lt;%26lt;endl;

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

cin %26gt;%26gt; age;

system(%26quot;cls%26quot;);

if(age%26lt;=15)

{

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

}

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

{

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

}

else{

cout %26lt;%26lt; %26quot;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!%26quot; %26lt;%26lt;endl;

}



system(%26quot;PAUSE%26quot;);

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;%26quot;female%26quot;;

if(gender=='b')

cout%26lt;%26lt;%26quot;male%26quot;;

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

system(%26quot;pause%26quot;);

return 0;

}

for more info about operators in c++ visit:

http://www.cplusplus.com/doc/tutorial/op鈥?/a>

++++++++++

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

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

Good programing :)
Help with program?
Try if (char gender[0] = 'a') {

. . .

}