.cpp(27): error C2181: illegal else without matching if cpp(37): error C2181: illegal else without matching if
hello,how to solve this problem I want to build a program about discount and total cost of order
below is the code.. it say the problem but i cant correct it thank you
#include < iostream >
using namespace std;
#define retailPrice 20
int main()
{
float quantity,discount;
float totalCost;
cout << "Welcome to GLAMOUR bookstore,Enjoy our cool promotion.\n";
cout << "Please enter the quantity of packages you have purchased:";
cin >> quantity;
{
if (quantity<0)
cout << "Sorry,quantity cannot be negative\n";
else if (0<=quantity && quantity<10)
discount = '0';
totalCost = quantity * retailPrice;
}
{
if (10<=quantity && quantity<=19)
discount = '20';
totalCost = quantity * retailPrice*0.8f;
else if (20<=quantity && quantity<=49)
discount = '30';
totalCost = quantity * retailPrice*0.7f;
}
{
if (50<=quantity && quantity<=99)
discount = '40';
totalCost = quantity * retailPrice*0.6f;
else if (quantity>=100)
discount = '50';
totalCost = quantity * retailPrice*0.5f;
}
cout << "Total cost of purchase = RM" << totalCost << ".\n";
cout << "discount =" << discount << "%\n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire