Help with if

closed account (Dy0fSL3A)
Hello, I am trying to write a program using the "if" function but I cant figure out how to make it work properly. The section I am working on looks like:

cout <<"Units sold: ";
int units_sold;
cin >> units_sold;
cin.ignore(10000, '\n');
if (units_sold <0 );
{
cout << "The number of units sold must be nonnegative."<< endl;
return 0;
}

However, even when I input a positive number for units_sold, it still shows the statement. I've also tried adding "else" after the brackets but it only makes another error "illegal else without matching if".

This is my first program I'm attempting to write sorry if I missed something obvious.
'if' is not a function; it's a control structure. And the problem is you have a semicolon after your if statement condition. Remove it and it should work as intended.
closed account (Dy0fSL3A)
Ok, got it thanks alot
Topic archived. No new replies allowed.