Hello, I am new to programming and working on a small program just testing something, this should raise b by one every 20 ticks but when I run it nothing happens.
#include <iostream>
using namespace std;
int x = 0;
int b = 0;
int main()
{
if(x==20){
b = b + 1;
x = 0;
}
else{
x = x++;
}
while(x==10){
cout << "Bacon count: " << b << endl;
}
return 0;
}
I think you have a conceptual misunderstanding - statements are executed in order once unless they are in a looping structure. Your if-else is not in a looping structure, so it is run once and never again. Because of this, x never changes to 10 and your while loop never runs either.
Also, x = x++; does not do what you think it does, in fact it does nothing at all. Just write ++x; by itself.
And for future reference, surround your code with code tags:
[code]
1 2 3 4 5 6
#include <iostream>
int main()
{
std::cout << "Syntax highlighting makes code easier to read" << std::endl;
}