Whatever you put within quotes is going to get printed out as text.
In line 13 - you're going to print "You entered a". You don't really need a variable there - you're printing out a text message in response to what the user entered.
Using a loop in this example would let the user enter multiple numbers. With a for loop you need to know ahead of time how many times you're going to go through the loop. With a while loop you can let the user enter until they choose to stop.
If you want to use a for loop, you can ask the user how many numbers they want to enter, then store that number in a variable. Then for the for loop, you'd
1) initialize the loop counter to 1
2) put the condition as the counter <= the number the user entered
3) increment the counter by 1
So if the user said they want to enter 5 numbers (userNumber = 5), the counter would start at one, one is <= the userNumber, so the code within the loop runs. The counter then increments to 2, this is still <= 5, so the code in the loop runs again. And so on ... until the counter increments to 6. 6 is not <= 5, so the loop will terminate after running 5 times and the program will move to the next line of code after the loop.
1 2 3 4 5 6
|
for (int counter = 1; counter <= userNumber; ++counter)
{
// your code here within the loop
// enter a number between 0 and 4 written out in letters
// if / else statements to print out the numeric equivalent
}
|