Can anyone help fix this code?

I'm new to coding and am having trouble with the code I'm working on.
b should raise by one every 20 ticks and loop continuously.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;


int x;
int b;
int i = 0;
int main()
{
    int x;
    int b;
    int i;


    while(i==0){
        if(x!=20){
            ++x;
        }
        else{
            ++b;
            x = 0;
        }
    };
    while(i==40){
        cout << "Bacon count: " << b << endl;
    }
    return 0;
}
You could have re-used this thread:
http://www.cplusplus.com/forum/general/113076/

Your code does work, the only problem is that the while loop on line 15 is infinite, so you never see the output on line 25.

Also, you don't need that semi-colon on line 23 - it doesn't hurt, but it's pointless.
Last edited on
Topic archived. No new replies allowed.