|
-
Feb 12th, 2003, 10:51 PM
#1
Thread Starter
New Member
Newbie Who Needs C++ help
Alright, this is only my 4th assignment in my C++ class, and I'm already stuck! Here's what I have to do:
Create a program that uses a series of "if/else" statements that will test the age of a person. I have to use compound conditional statements to determine if a person is over 21 and a female (using the &&). Then, I have to use the || operator to test for males or over 21.
Here's my basic coding so far (which is completely messed up) and thanks in advance for any help:
#include <iostream>
using namespace std;
void main()
{
int age;// creates a variable called age
char g;//creates a variable called mf
cout<<"Are you m (for male) or f (for female)? ";//inputs a message on the terminal
blah:
cin>>g;
if (g != 'm' && g != 'f')
{cout<<"Are you an alien? Please enter again\n"; goto blah;}
else cout<<"Hello, how old you are? ";//inputs a message on the terminal
cin>>age;//waits for user input
if (g == 'm')
if (age > 21)
{cout<<"You are a male over 21!\n"; }
if (g = 'm' && age < 21 || age > 21)
{cout<<"You are either a male or are under 21!\n";}
if (g =='f')
if (age > 21)
{cout<<"You are a pretty woman over 21!\n" ;}
else {cout<<"You are under 21, and a female!\n";}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|