I'm supposed to be using nested if/else statements in my assignment. My IF statements execute just fine, but when I add "else" anywhere it comes up with a red squiggly line under it. Is it because I'm using the brackets wrong?
{
const int package = 99;
double quantity, total1, total2, total4;
cout << "How many units were sold?\n";
cin >> quantity;
if (quantity >= 1 && quantity <= 19);
{
total1 = package * quantity - (.2 * package * quantity);
cout << "Sale total: " << total1 << endl;
}
else if (quantity >= 20 && quantity <= 99);
{
total2 = package * quantity - (.3 * package * quantity);
cout << "Sale total: " << total2 << endl;
}
else (quantity >= 100);
{
total4 = package * quantity - (.5 * package * quantity);
cout << "Sale total: " << total4 << endl;
}
The errors I'm getting back from the lines using "else" are:
- E0127 expected a statement
- C2181 illegal else without matching if
Aucun commentaire:
Enregistrer un commentaire