Help with while loop

I'm writing a program with a while loop. Whenever I compile it and test it, if I enter a number greater then 0 it couts "enter a positive number". If I enter a negative number it doesn't do anything. My code is okay but im confused from lines 12-16. Some help would be appreciated! Thanks so much.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #include <iostream>
using namespace std;

int main()
{	//package is cost of a unit
	const int PACKAGE = 99;
	int units_sold = 0;

	cout << "How many units have been sold?";
	cin >> units_sold;

	while (units_sold <= 0);
	{
		cout << "Enter a positive number.";
		cin >> units_sold;
	}
	if (units_sold >= 1 && units_sold < 10)
	// and so on .. 
Last edited on
Line 12 take out the semicolon :)
if(unit_sold<0)continue; ._.)a
WOW. Thank you so much! Although I feel like such a beginner. But every time I compiled it, I received no error? Wouldn't it have given me a syntax error? May I ask why it didn't?
Because it an algorithm error :o some good compilers provide some warning
It's technically valid code. You just have an empty while loop followed by an arbitrary scope containing some code. I know clang will warn for those kinds of statements with -Wempty-body or something similar.
Topic archived. No new replies allowed.