Ok so I'm trying to make a program which will tell that how many pancakes 10 people ate indivdually. But I can't seem to understand that why is 'y' not incrementing?
#include <iostream>
usingnamespace std;
int main()
{
int hamza [9];
int y;
for (y=5; y<=14; y++)
int talha [9];
int x;
cout << "Person - Pancakes\n";
for(x=1; x<=10; x++)
{
cout << x <<" ------- "<< y << endl;
}
return 0;
}
It seems that you are not handling the iteration of your for loop anywhere. Try appending the following onto your Y Loop: for (y=5; y<=14; y++) {}
This will ensure that no confusion is made when compiling and running your code.
In addition, ensure that when you define your Y variable that the value is 5: int y = 5;
Chriscpp also offers a solid solution: removing the excess code and incrementing both the values at the same time. I would have offered this solution myself but I was unsure if you wanted both the X and Y incrementation to be the same.
In any case, may I offer an extension to chriscpp's method:
1 2 3 4
for(x=1 && y=5; x<=10 && y<=14; x++,y++)
{
cout << x <<" ------- "<< y << endl;
}
Thanks Chriscpp and everyone else. Thats was exactly what I wanted my code to to.
So now I'm trying to make user enter the number of pancakes eated by the person1, person 2 and so on.
So I made this. Its working fine. But after entering the 10 values of number of pancakes eaten by each person. The prog doesnt end. It starts asking for person 1 again. What to do?
#include <iostream>
usingnamespace std;
int main()
{
int x;
int y;
int sum;
for (x=1; x<=10; x++)
for (y=1; y<=10; y++)
{
cout << "How many pancakes did person " << y << " eat?\n";
cin >> x;
}
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int x;
int y;
int sum;
for (x=1; x<=10; x++)
{
//Ensure you are handling this loop. Or it will call the next loop 10 times.
//Add braces.
}
for (y=1; y<=10; y++)
{
cout << "How many pancakes did person " << y << " eat?\n";
cin >> x;
}
return 0;
}
This edit should make the program end at the correct time.
Garry++