While Loop statement help (not hacking related AT ALL.)
So, I've decided to create a program. The program will say for start "would you like to buy a bread for 1 coin? <y/n>" and if I select yes, then I buy 1 bread for 1 coin (i have 100 coin and 1 bread for default).
I made this program within 1 minute. It was WAY too easy, so I decided to crank up the heat a little by adding some while loops.
This time, I wanted to add that at the end of purchase, the program will ask, "would you like to buy another bread? <y/n>", then, if I say "yes", then I will buy ANOTHER bread for 1 coin, thus, resulting in 98 coins and 2 breads now. (Hope you understand this). If I select no, then the program will just say "awww that's too bad" then terminate by the "return 0;" statement.
This is my coding.
DEBUGGING SCREENSHOTS to prove something is DEFINITELY wrong.
#1

#2 (after clicking "y")

infinite loop? lol
Could someone please tell me what part of coding I'm screwing up at?
In this case @giniyat101
I made this program within 1 minute. It was WAY too easy, so I decided to crank up the heat a little by adding some while loops.
This time, I wanted to add that at the end of purchase, the program will ask, "would you like to buy another bread? <y/n>", then, if I say "yes", then I will buy ANOTHER bread for 1 coin, thus, resulting in 98 coins and 2 breads now. (Hope you understand this). If I select no, then the program will just say "awww that's too bad" then terminate by the "return 0;" statement.
This is my coding.
Code:
#include <iostream>
using namespace std;
int main()
{
int c=100, b=1;
char choice='y';
char AnotherChoice='x';
cout << "Welcome to our store! Would you like to buy a bread for 1 coin? <y/n> ";
cin >> choice;
while(choice=='y')
if(AnotherChoice=='y')
{
c--;
b++;
cout << "Here you go! " << endl;
}
else
{
c=c;
b=b;
cout << "That's too bad. " << endl;
}
cout << "COINS: " << c << endl;
cout << "BREAD: " << b << endl;
cout << endl;
cout << "Would you like to buy another bread for 1 coin? <y/n> ";
system("pause");
return 0;
}
#1

#2 (after clicking "y")

infinite loop? lol
Could someone please tell me what part of coding I'm screwing up at?
In this case @giniyat101
@
[/B]
