Wondering why compile takes so long, what am I doing wrong

Just starting out and trying to figure out where I am doing this wrong, takes more than 2 seconds to compile, what am I doing wrong, just starting out and messing around with the while loop. Thanks.

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
#include <iostream>

using namespace std;

int main()
{
    int num;
    int total;
    int counter = 1;
    int enter;

    cout << "How many times do you want to play?\n"
         << "Enter Number Here: ";
    cin >> num;

    total= num;

    cout << "You want to play to " << total <<" times.";

    while (counter <= total){
            cout << "\nEnter the Number one.\n";
            cin >> enter;
            ++counter;
    }

}
How fast do you wanna go? lol It takes around a second for me. It depends on your computer
Last edited on
ha ha. does the code look ok, I am curious if I missing anything, have the variable enter seems kind of odd, I was wondering if there was a better way to do it.
Well, I'm not sure what you're trying to do, so I can't tell you if there's anything wrong.

Although cin >> num; total= num; kind of stands out. You don't really need a variable called num. You can just input total.

And don't forget to "return 0;" in the end. int main() is a function and it must have a return value. :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
	int total;
	int counter = 1;
	int enter;

	cout << "How many times do you want to play?\n" << "Enter Number Here: ";
	cin >> total;

	cout << "You want to play to " << total << " times.";

	while (counter <= total) 
	{
		cout << "\nEnter the Number one.\n";
		cin >> enter;
		++counter;
	}
	return 0;
}
Last edited on
awesome, that is what I was looking for, I don't know what I want either :0) just trying to figure out the logic and make sure I am writing the cleanest I can, and I see what you are saying, why make something equal to another variable when its not going to change, DOH. thank you.
Nothing is wrong you could add "stdafx.h" but I don't know if your IDE would allow it stdafx is a precompiled header thing which will make it so the compiler doesn't have to start from scratch and re compile everything.
don't forget to "return 0;"
Main function is a special case and is threated as returning 0 if no explicit return clause found.

you could add "stdafx.h"
You should actually add stuff you need in that header for it to be of any use.
Topic archived. No new replies allowed.