Pancake Glutton v2

Ok! I'm almost done with this simple program lol


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

The if statement to find the highest value works, However the if statement to find the lowest value does not work correctly!! It always gives me the last number that I imput into the array as the lowest value, which sometimes it is not. Please, can one look over the code and make sure to read the comments!? thankyou (:

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
35
36
37
38
39
40
41
42
// 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 in the array
	int Lowest_Value = 0; //Variable for the lowest value haha
	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];
		//I made the lowest_value equal to the minimum element in the array (aka the first number imputed)
		Lowest_Value = Pancakes[0]; 
		//if statement to find the highest value
		//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];
		}
		//If statement to find the minimum value
		//If the number imputed is lower than the first number imputed, it changed to that value
		if (Pancakes[i] < Lowest_Value)
		{
			Lowest_Value = Pancakes[i];
		}
	}

	cout << "The highest number of pancakes eaten is " << temp << endl
	<< "The lowest number of pancakes easten is " << Lowest_Value << endl;
	
	system("PAUSE");
	return 0;
}
Last edited on
On line 14, set "Lowest_Value" as 10. It should work, as long as the lowest number of pancakes eaten is smaller than 10. Just try making it a high number so that the numbers of pancakes is lower than it.
Last edited on
Another thing you could do is add:
1
2
3
4
if(i<=0)
{
Lowest_Value = Pancakes[i];
}

right before the if statement that's causing the problem.
Topic archived. No new replies allowed.