Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

I need some help

I am just trying to learn, I am not advanced at all, so could someone look this over and tell me what I've done wrong, and how to fix it please.

#include <iostream>
using namespace std;
int main()
{
unsigned short int age;
cout << "Age\t";
cin >> age;
switch (age)
{
case M14:
cout << "14\n";
break;
case M15:
cout << "15\n";
}
return 0;
}
[481 byte] By [sic0198] at [2007-11-11 8:49:24]
# 1 Re: I need some help
It easier to help if you state what it is you're having problems with, but on reading your code I wonder what M14 and M15 are.
If you remove the M:s it should work.
Or alternately:
#define M14 (14)
#define M15 (15)
Or
const int M14 = 14;
const int M15 = 15;

Rune
Rune Bivrin at 2007-11-11 21:01:03 >
# 2 Re: I need some help
As Rune said, you need to get rid of the M. Notice also that the second case doesn't have a break statement at the end and that yoru switch doesn't have a defalt case either. This could certainly cause bugs.
Danny at 2007-11-11 21:01:57 >
# 3 Re: I need some help
Thanks for your replies.

I wanted to be able to respond with M14 or M15 etc. This stands for M15 = male 15 and male 16. I think I will sae an age variable to int, and a sex variable to char. if I type cout << "Age:\t"; and on the line under that type cin >> age;
I want to ask two questions on one line how would I do that? I want to get input from both questions?
sic0198 at 2007-11-11 21:02:57 >
# 4 Re: I need some help
cout<<"please enter age and sex (m, f) "
cin >> age >> sex;

don't think that representing sex as a single char is safe enough. It's better to store it as a string.
Danny at 2007-11-11 21:04:02 >
# 5 Re: I need some help
I understand what you guys are saying, and I will try it. Thanks
sic0198 at 2007-11-11 21:05:06 >