Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
arrays
Write a program that asks the user to enter the number of pancakes eaten for breakfast by 10 different people (Person 1, Person 2, ..., Person 10)
Once the data has been entered the program must analyze the data and output which person ate the most pancakes for breakfast.
★ Modify the program so that it also outputs which person ate the least number of pancakes for breakfast.
★★★★ Modify the program so that it outputs a list in order of number of pancakes eaten of all 10 people.
i.e.
Person 4: ate 10 pancakes
Person 3: ate 7 pancakes
Person 8: ate 4 pancakes
...
Person 5: ate 0 pancakes
I wrote a little bit of it, but I'm so confused on how to write the loop that finds who ate the most pancakes and thenthe program identifies the name of the person who ate the most pancakes. Could one look at my code and give me some feedback on how to make that loop? Also, Is it possible to put custon names to elements in an array (i.e. element 1 = Player 1, element 2 = Person 2 etc.)? I want to do this so that the program will recognize who ate the most.
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 30 31 32 33 34
|
// Pancake Glutton.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//The array called "Pancakes" has 10 elements for the 10 people
int Pancakes[9], NumberofPancakes, max_NumberPancakes = 0, count = 0;
cout << "Please enter in the number of pancakes eaten for breakfast by 10 different people\n";
/*Loop that finds the person who ate the most pancakes and
finds the name of that player */
for(int i = 0; i < 9; i ++)
{
//This does not work correctly b/c I'm so confused xD
count++;
cin >> Pancakes[i];
if(Pancakes[i] = max_NumberPancakes)
{
max_NumberPancakes = Pancakes[i];
}
if(Pancakes[i] = max_NumberPancakes)
{
cout << count << " Ate the highest number of pancakes at " << max_NumberPancakes << endl;
}
}
system("PAUSE");
return 0;
}
|