Ok so I did the thing in the begginers excercises on this website. I got to the pancake one and I did the code right but I know knowing how to do it but not knowing why it works is as bad as not knowing how to do it. so here is the code
#include "stdafx.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include<stdlib.h>
usingnamespace std;
int main()
{
int pcakes[10];
int max = 0;
for (int i = 0; i < 10; ++i){
cout << "enter the pancake amount for person" << i + 1 << endl;
cin >> pcakes[i];
if (pcakes[i] > max)
{
max = pcakes[i];
}
}
cout << "the max number is " << max << endl;
system("pause");
return 0;
}
the other libraries is there from other things..but my question is why does that work, it does not make sense to me , if pcakes[i] si greater then max then max = pcakes[i]. but wouldnt that mean that if pcakes is greater which it is if its above 0 then pcakes would be 0 since max is 0?
Ok I am dumb, after asking it on here i see now, max becomes pcakes[i]. but my new question is...how does it know to give max the highest value? since there is 10 other values in pcakes?