Alright, I have an assignment that tells me to do this:
Write a program that asks the user for a number of hamburgers they would like to eat. The program should use a loop to display the following line for every hambuger they "eat". For example if the user entered 5 the output should look like this:
You ate hamburger number 1 and absorbed 1200 calories!
You ate hamburger number 2 and absorbed 2400 calories!
You ate hamburger number 3 and absorbed 3600 calories!
You ate hamburger number 4 and absorbed 4800 calories!
You ate hamburger number 5 and absorbed 6000 calories!
The program should use a loop display a line for every hamburger the user "eats". Be sure that you use variables to calculate and/or display the number of hamburgers and the number of calories (each hamburger is 1200 calories).
I cannot figure out which loop to use to make it work...I've tried while and for, but i'm not sure how to make it work for "infinite" numbers. Could anyone point me in the right direction? I don't want you to write the code for me...just help would be nice.
Here's some logic: make a variable to hold the number of hamburgers
input to the variable
for each hamburger
....print "You ate hamburger number "
....print current loop index
....print " and absorbed "
....print current loop index times 1200
....print " calories!"
....print new line
I used a for loop because they are the loop of choice for looping X times and keeping track of the current loop index:
1 2 3 4
for(unsignedint i = 0; i < times; ++i)
{
//code to do each time
}