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";}
}
Re: Newbie Who Needs C++ help
Please sort out the code before you post. There are some things that make it hard to read, and even though I enjoy helping newbies I don't enjoy deciphering code. So please sort out obvious inconcistencies (such as this line:
char g;//creates a variable called mf
which obviously doesn't create a variable called mf) and then repost the code. Then I will help you.
Also are you sure that it is
"Then, I have to use the || operator to test for males or over 21." and not "under 21" (or maybe under 21 already when it comes to women)?
And use [code][/code] tags to preserve the formatting of your code and make sure that the formatting is right in the first place:
{cout<< ...
is bad formatting. Bad formatting has very many problems, your biggest of those is probably that few people on boards like this read such code and bother to answer your questions.
Anjari: we don't like doing your homework for you, questions like
Quote:
I have to do x, how do I do that?
are not welcome. But if you say:
Quote:
I have to do x. I used approach y and have this (properly formatted) code:
Code:
code code code
this part doesn't do what it should
more code code code
Do you have an idea what the problem could be?
then you can rest assured that you'll get an answer.