Pancake Glutton

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;
}



*use == if you want to compare values (instead of single =)

*you have: (in pseudocode)
if pancakes is equal to max
     then max = pancakes
end if

which is quite pointless. because no values are changed ever.

*this will start you a bit: ( i did not test this)
1
2
3
4
5
6
7
8
9
10
for(int i = 1; i <= 10; i ++)
	{ 
		cin >> Pancakes[i];
		if (pancakes[i]>max_NumberPancakes) 
                {
                 max_NumberPancakes=pancakes[i];count=i;
                 }
         }
	cout << count << " Ate the highest number of pancakes at " << max_NumberPancakes << endl; 
		
Last edited on
Ok Yea I didn't think that made sense haha! Thanks for the info!! Is there a way to name an element like the first number I enter = Person 1 and the second number = Person 2? On my cout line cout << count << " Ate the highest number of pancakes at " << max_NumberPancakes << endl;, the count is supposed to refer to the players name.
Last edited on
count is the number that displays which player ate the most pancakes.
since you'r not inputting a real name for them you can't output that.
DID IT! FINALLY LOL... just read my commments! thanks for all your imput gelatine !

UPDATE: "Run-Time Check Failure #2 - Stack around the variable 'Pancakes' was corrupted." whats this mean?

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
// 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];
	int temp = 0; //Temp is the lowest possible value 
	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
	for(int i = 0; i <= 9; i++)
	{
		cin >> Pancakes[i];
		/*If the value entered is greater than temp, the value of temp changes to that and so on... */
		if (Pancakes[i] > temp) 
		{
			temp = Pancakes[i];
		}
	}

	cout << "The highest number of pancakes eaten is " << temp << endl;
	
	system("PAUSE");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.