My assignment is:
Ask the user for a number. Use a switch statement to process the number entered:
if the user enters 2, print "shoe"
if the user enters 4, print "door"
if the user enters 6, print "sticks"
if the user enters 8, print "straight"
if the user enters 10, print "big fat hen"
if the user enters any other number, print out "Not much into kids' rhymes, are you?"
Here's what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include<iostream>
using namespace std;
int main()
{
char number;
cout << "Please enter a number" << endl;
cin>> number;
cout << number << endl;
switch (number)
{ case 2: cout << "shoe";
break;
case 4: cout << "door";
break;
case 6: cout << "sticks";
break;
case 8: cout << "straight";
break;
case 10: cout << "big fat hen";
break;
}
}
1,1 Top
|
I've never done a switch statement before so I know this isn't completley right. I'm also not sure how to have it print out the code for all the other numbers that aren't listed.