Question: C++; help with string and if - else conditions. #include using namespace std; int main() { float byoitem, halfItem, basePrice, taxRate, discountedPrice, grandTotal, tempTotal; string
C++; help with string and if - else conditions.
#include
using namespace std;
int main()
{
float byoitem, halfItem, basePrice, taxRate, discountedPrice, grandTotal, tempTotal;
string Y, y, N, n, clubCard;
const float discount = .1;
// screen I/O
cout << "Enter price of first item: ";
cin >> byoitem;
cout << "Enter price of second item: ";
cin >> halfItem;
cout << "Does the customer have a club card? (Y/N): ";
cin >> clubCard;
cout << "Enter tax rate, e.g. 5.5 for 5.5% tax: ";
cin >> taxRate;
tempTotal = byoitem + (halfItem * .5);
if (clubCard = "Y" || clubCard = "y")
{discountedPrice = tempTotal - (tempTotal * discount / 100);
grandTotal = discountedPrice + (discountedPrice * taxRate);}
else (clubCard = "N" || clubCard = "n")
{grandTotal = tempTotal * taxRate}
cout << "Base price: " << basePrice << endl;
cout << "Price after discounts: " << discountedPrice << endl;
cout << "Total price: " << grandTotal << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
