Question

#include using namespace std; int main() {     //declare variables and named constant     int cupsPurchased...

#include

using namespace std;

int main()

{

    //declare variables and named constant

    int cupsPurchased =0;

    int platesPurchased =0;

    double cupPrice =0.0;

    double platePrice =0.0;

    double totalCupCost= 0.0;

    double totalPlateCost= 0.0;

    double subtotal =0.0;

    double totalCost =0.0;

    const double TAX_RATE = .055;

    //Enter input items

    cout << "Cup price: ";

    cin >> cupPrice;

    cout << "Plate price: ";

    cin >> platePrice;

    cout << "Cups purchased";

    cin >> cupsPurchased;

    cout << "Plates purchased: ";

    cin >> platesPurchased;

    //calculate the total cup cost, total plate

    //cost, the subtotal, and the total cost

    totalCupCost = cupsPurchased * cupPrice;

    totalPlateCost = platesPurchased * platePrice;

    subtotal = totalCupCost + totalPlateCost;

    totalCost = subtotal * TAX_RATE + subtotal;

    //display total cost

    cout << "Total cost: $" <

    return 0;

}

1. Simple calculator

Modify above code to include all 5 different math operations below:

(Add, subtract, multiply, divide and modulus (+, -, *, /, %))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main()
{

double cupsPurchased =0;

double platesPurchased =0;

int cupPrice =0.0; // change the datatype of cupPrice from double to int as '%' operator will not support double datatype

double platePrice =0.0;

int totalCupCost= 0.0; // change the datatype of totalCupCost from double to int as '%' operator will not support double datatype

double totalPlateCost= 0.0;

double subtotal =0.0;

double totalCost =0.0;
  
double totaltax = 0.0; // variable to store the total tax value
  
double modulo = 0.0; // variable to store the modulo result

const double TAX_RATE = .055;
  

//Enter input items

cout << "Cup price: ";

cin >> cupPrice;

cout << "Plate price: ";

cin >> platePrice;

cout << "Cups purchased";

cin >> cupsPurchased;

cout << "Plates purchased: ";

cin >> platesPurchased;

//calculate the total cup cost, total plate

//cost, the subtotal, and the total cost

totalCupCost = cupsPurchased * cupPrice;

totalPlateCost = platesPurchased * platePrice;

subtotal = totalCupCost + totalPlateCost;

totalCost = subtotal * TAX_RATE + subtotal;
  
//calculate total tax on the purchase of the above goods
  
totaltax = totalCost - subtotal;
  
//calculate totalCupCost % cupPrice
  
modulo = totalCupCost % cupPrice; // this must be equal to zero because if we multiply totalCupCost with cupprice the remainder will be zero
  

//display total cost

cout << "Total cost: $" << totalCost;
  
//display total tax
cout << "Total tax on the purchase is: $" << totaltax;
  
  
//display the modulo value which is zero
  
cout << "the modulo value is : " << modulo;
  
  
  


return 0;
}

Add a comment
Know the answer?
Add Answer to:
#include using namespace std; int main() {     //declare variables and named constant     int cupsPurchased...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • FILL IN THE BLANKS #include #include <> *BLANK* using namespace std; int main() {     const...

    FILL IN THE BLANKS #include #include <> *BLANK* using namespace std; int main() {     const double HOURLY_RATE = 15;     string input_str;     cout << "Enter days of attendance: " << endl;    *BLANK* (cin, input_str);     stringstream input_stream();     int total_hours = 0;     while(!input_stream.())*BLANK*     {         int hours;         string day;         input_stream >> day;         if(day ==  *BLANK*|| day == *BLANK*)         {             hours = 5;         }         *BLANK*(day == "Tuesday" || day == "Thursday")         {             hours = 4;         }         else if(day ==...

  • im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int...

    im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...

  • Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() {...

    Use this code to create multiple functions. #include<iostream> #include<iomanip> #include<fstream> using namespace std; int main() { cout << fixed << showpoint << setprecision(2); ofstream outFile; outFile.open("Feras's.txt"); outFile << "..Skinny Feras's Restaurant ..\n\n" << endl; int choise=10, quantity; float paid, SubTotal=0, Tax = .10, Total, RM, more; while(choise!=0) { system("cls"); cout << "\t**Welcome To Skinny Alsaif Restaurant Lol**" << endl; cout << "\nWhat would you like to have?" << endl; cout << "1. Burger." << endl; cout << "2. Pizza." <<...

  • Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0,...

    Flow chart of this program #include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0, ave-ee, int locmx, locmn int n; cout <<"Enter the number of students: "<<endl; cin >> ni double listln]; double max-0; double min-e; for (int i-e ; i<n ;i++) cout<s enter the gpa: "<cendli cin>>listli]; while (listlile i listli1>4) cout<s error,Try again "<cendl; cin>listlil: sun+=list[i]; N1 if (listli]>max) for(int isin itt) max=list [i]; 10cmx=1+1 ; else if (list [i] min) min=list [i]; locmn-i+1; ave sum/n;...

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

  • #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS =...

    #include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...

  • what is the output for the following code? explain the steps. /*#include <iostream> using namespace std;...

    what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...

  • #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

    #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;        int dday;        int dyear;       public:       void setdate (int month, int day, int year);    int getday()const;    int getmonth()const;    int getyear()const;    int printdate()const;    bool isleapyear(int year);    dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) {    int numofdays;    if (year<=2008)    {    dyear=year;...

  • #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0;...

    #include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT