This should help. Note I am using double for prices.
#include <iostream>
using namespace std;
int main()
{
char name[50];
int page, pageSum = 0;
double prtotal, prtotalSum = 0;
int option;
char answer;
do {
cout << "\n\nPlease enter your name: ";
cin >> name;
cout << "\n\nWelcome to Printworld " << name << endl;
cout << "\n\nHow many pages would you like to print? ";
cin >> page;
pageSum += page;
if (page <= 100)
{
cout << "\n\nThat will be " << page << "*$0.10=$" << 0.10 * page << endl;
prtotal = 0.10 * page;
}
else
{
cout << "\n\nThat will be " << page << "*$0.05=$" << 0.05 * page << endl;
prtotal = 0.05 * page;
}
// binding menu
cout << "\n\nFor binding, which option would you like to select?\n" << endl;
cout << "1) Hardcopy $50.50" << endl;
cout << "2) Punch and Bind $40.50" << endl;
cout << "3) Stitched Binding $25\n" << endl;
cout << "4) No Binding $0\n" << endl;
// Prompting user to enter an option according to menu
cout << "Please select an option : ";
cin >> option;
if (option == 1) // Checking if user selected option 1
{
// Display hardcopy binding
cout << "\nHardcopy $50.50+" << prtotal << "=$" << 50.50 + prtotal << endl;
prtotal += 50.50;
}
else if (option == 2) // Checking if user selected option 2
{
// Displaying punch and bind
cout << "\nPunch and Bind $40.50+$" << prtotal << "=$" << 40.50 + prtotal << endl;
prtotal += 40.50;
}
else if (option == 3) // Checking if user selected option 3
{
// displaying stiched binding
cout << "\nStitched Binding $25+$" << prtotal << "=$" << 25 + prtotal << endl;
prtotal += 25;
}
else if (option == 4) // Checking if user selected option 4
{
// displaying no binding
cout << "\nNo Binding $0+$" << prtotal << "=$" << 0 + prtotal << endl;
}
else // if user has entered invalid choice (other than 1,2,3 or 4)
{
// Displaying error message
cout << "\nInvalid Option entered" << endl;
}
prtotalSum += prtotal;
// bool to loop the process
cout << "\nDo you want to try again? (Y/N) ";
cin >> answer;
while (answer != 'n' && answer != 'N' && answer != 'Y' && answer != 'y')
{
// error validation
cout << "\nYou must enter (Y/N): ";
cin >> answer;
}
} while (answer != 'n' && answer != 'N');
cout << "\nTotal Pages: " << pageSum << endl;
cout << "\nTotal Price: " << prtotalSum << endl;
}
2
solved Adding numbers and displaying a summary in c++ [closed]