I dont know why my min variable is keep showing zero (0). The min variable meant show what is the lowest pancake that was ate. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I dont know why my min variable is keep showing zero (0). The min variable meant show what is the lowest pancake that was ate.

#include <iostream> using namespace std; int main() { int pancake[5]; int max=pancake[0]; int min=pancake[0]; int i; cout<<"Enter the number of pancake that the first person ate"<<endl; cin>>pancake[0]; if (pancake[i]<min){ min=pancake[i]; } if (pancake[i]>max){ max=pancake[i]; } for (i=1; i<5;i++){ cout << "Input the number of pancake that next person ate "<<endl; cin >> pancake[i]; // for ( int k=0;k<5;k++){// if (pancake[i]<min){ min=pancake[i]; } if (pancake[i]>max){ max=pancake[i]; } } for(int j=0; j<5;j++){ cout <<"Person "<<j<<": "<<pancake[j] << endl; } cout << "The greatest amount of pancake that was eaten was "<< max << endl; cout << "The least amount of pancake that was eaten was " <<min<<endl; }

29th Apr 2020, 7:36 AM
Deniel Moises Tolibas
1 Answer
+ 1
You set the min and max variables to pancake[0] at the top when the pancake array was empty (and it had garbage values because it was not zero initialized). You can fix it by setting the min and max variable equal to pancake[0] after cin >> pancake[0];
29th Apr 2020, 8:09 AM
Damyian G
Damyian G - avatar