Hey guys i have this program that i need to write for class. here are the instructions:
Write a function called foo that asks the user for their age. Pass the age value to a function called showAge that uses a select case structure to print out the following: If the age is 0-12 print out "You are still a child. If the age is 13 - 19 print out "You are a teenager. If the age is 20 - 40 print "You are an adult" anything else print "You are starting to become mature
This is what i have, its works but i dont see why my teach wont let me use an if else..... please help me. Is this the right solution?
Write a function called foo that asks the user for their age. Pass the age value to a function called showAge that uses a select case structure to print out the following: If the age is 0-12 print out "You are still a child. If the age is 13 - 19 print out "You are a teenager. If the age is 20 - 40 print "You are an adult" anything else print "You are starting to become mature
This is what i have, its works but i dont see why my teach wont let me use an if else..... please help me. Is this the right solution?
Code:
#include <iostream>
using namespace std;
int foo ();
int x;
int showAge ();
int main()
{
foo();
}
int foo()
{
cout << "Please Enter Your Age:" << endl;
cin >> x;
showAge();
return x;
}
int showAge ()
{
switch ( x )
{
case 1:
cout << endl << "You are still a child." << endl;
break;
case 2:
cout << endl << "You are still a child." << endl;
break;
case 3:
cout << endl << "You are still a child." << endl;
break;
case 4:
cout << endl << "You are still a child." << endl;
break;
case 5:
cout << endl << "You are still a child." << endl;
break;
case 6:
cout << endl << "You are still a child." << endl;
break;
case 7:
cout << endl << "You are still a child." << endl;
break;
case 8:
cout << endl << "You are still a child." << endl;
break;
case 9:
cout << endl << "You are still a child." << endl;
break;
case 10:
cout << endl << "You are still a child." << endl;
break;
case 11:
cout << endl << "You are still a child." << endl;
break;
case 12:
cout << endl << "You are still a child." << endl;
break;
case 13:
cout << endl << "You are a teenager." << endl;
break;
case 14:
cout << endl << "You are a teenager." << endl;
break;
case 15:
cout << endl << "You are a teenager." << endl;
break;
case 16:
cout << endl << "You are a teenager." << endl;
break;
case 17:
cout << endl << "You are a teenager." << endl;
break;
case 18:
cout << endl << "You are a teenager." << endl;
break;
case 19:
cout << endl << "You are a teenager." << endl;
break;
case 20:
cout << endl << "You are an adult" << endl;
break;
case 21:
cout << endl << "You are an adult" << endl;
break;
case 22:
cout << endl << "You are an adult" << endl;
break;
case 23:
cout << endl << "You are an adult" << endl;
break;
case 24:
cout << endl << "You are an adult" << endl;
break;
case 25:
cout << endl << "You are an adult" << endl;
break;
case 26:
cout << endl << "You are an adult" << endl;
break;
case 27:
cout << endl << "You are an adult" << endl;
break;
case 28:
cout << endl << "You are an adult" << endl;
break;
case 29:
cout << endl << "You are an adult" << endl;
break;
case 30:
cout << endl << "You are an adult" << endl;
break;
case 31:
cout << endl << "You are an adult" << endl;
break;
case 32:
cout << endl << "You are an adult" << endl;
break;
case 33:
cout << endl << "You are an adult" << endl;
break;
case 34:
cout << endl << "You are an adult" << endl;
break;
case 35:
cout << endl << "You are an adult" << endl;
break;
case 36:
cout << endl << "You are an adult" << endl;
break;
case 37:
cout << endl << "You are an adult" << endl;
break;
case 38:
cout << endl << "You are an adult" << endl;
break;
case 39:
cout << endl << "You are an adult" << endl;
break;
case 40:
cout << endl << "You are an adult" << endl;
break;
default:
cout << endl << "ou are starting to become mature or too old" << endl;
}
return x;
}
Comment