Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I post this question last night, but some one gave me a wrong answer. I Hope som

ID: 3804904 • Letter: I

Question

I post this question last night, but some one gave me a wrong answer. I Hope someone could give me the right code.

Write a program that will calculate the cost of purchasing a meal. This program will include decisions and loops. Details of the program are as follows:

Your menu items only include the following food with the accompanying price:

Yum Yum Burger = .99

Grease Yum Fries = .79

Soda Yum = 1.09

Allow the user of the program to purchase any quantity of these items in one order.

Allow the user of the program to purchase one or more types of these items in one order.

After the order is placed, calculate total and add a 6% sales tax.

Print to the screen a receipt showing the total purchase price.

The Pseudocode (Note: module = function and ref = &)

int main()

{

Create Variables

Call declareVariables(endProgram, endOrder, totalBurger, totalFry, totalSoda, total, tax, subtotal, option, burgerCount, fryCount, sodaCount)

            //Loop to run program again

            While endProgram == “no”

                        Call resetVariables(totalBurger, totalFry, totalSoda, total, tax, subtotal)                      

                        //Loop to take in order

                        While endOrder == “no”

Display “Enter 1 for Yum Yum Burger”

Display “Enter 2 for Grease Yum Fries”

Display “Enter 3 for Soda Yum”

                                    Input option

                                                If option == 1 Then

                                                           Call getBurger(totalBurger, burgerCount)

                                                else If option == 2 Then

                                                           Call getFry(totalFry, fryCount)

                                               else If option == 3 Then

                                                           Call getSoda(totalSoda, sodaCount)

                                               end else         

Display “Do you want to end your order? (Enter no to add more items: )”

Input endOrder

                        End While

                        Call calcTotal(burgerTotal, fryTotal, sodaTotal, total, subtotal, tax)

                        Call printReceipt(total)

                        Display “Do you want to end the program? (Enter no to process a new order)”

                        Input endProgram

End While     

return 0; // no need for system(“pause”);

}

Module declareVariables(String Ref endProgram, String Ref endOrder, Real Ref totalBurger, Real Ref totalFry, Real Ref totalSoda, Real Ref total, Real Ref tax, Real Ref subtotal, Real Ref option, Real Ref burgerCount, Real Ref fryCount, Real Ref sodaCount)

Declare String endProgram = “no”

            Declare String endOrder = “no”

            Declare Real totalBurger = 0

            Declare Real totalFry = 0

            Declare Real totalSoda = 0

            Declare Real total = 0

            Declare Real tax = 0

            Declare Real subtotal = 0

            Declare Integer option = 0

            Declare Integer burgerCount = 0

            Declare Integer fryCount = 0

            Declare Integer sodaCount = 0

End Module

Module resetVariables (Real Ref totalBurger, Real Ref totalFry, Real Ref totalSoda, Real Ref total, Real Ref tax, Real Ref subtotal) //reset variables

            totalBurger = 0

            totalFry = 0

            totalSoda = 0

            total = 0

            tax = 0

            subtotal = 0

End Module

Module getBurger(Real Ref totalBurger, Integer burgerCount)

            Display “Enter the number of burgers you want”

            Input burgerCount     

            Set totalBurger = totalBurger + burgerCount * .99

End Module

Module getFry(Real Ref totalFry, Integer fryCount)

            Display “Enter the number of fries you want”

            Input fryCount           

            Set totalFry = totalFry + fryCount * .79

End Module

Module getSoda(Real Ref totalSoda, Integer sodaCount)

            Display “Enter the number of sodas you want”

            Input sodaCount        

            Set totalSoda = totalSoda + sodaCount * 1.09

End Module

Module calcTotal(Real totalBurger, Real totalFry, Real totalSoda, Real Ref total, Real subtotal, Real tax)

            Set subtotal = totalBurger + totalFry + totalSoda

            Set tax = subtotal * .06

            Set total = subtotal + tax

End Module

Module printReceipt(Real total)

            Display “Your total is $”, total

End Module

Explanation / Answer

/* In the Question, the variable endOrder also needs to be reset to "no" after endProgram is entered as no, or else the program won't take inputs for the second order onwards. */

#include <iostream>

#include <stdio.h>

#include <ctype.h>

#include <string.h>

using namespace std;

void declareVariables(string* endProgram, string* endOrder, float* totalBurger, float* totalFry, float* totalSoda,float* total, float* tax, float* subtotal, int* option, int* burgerCount, int* fryCount, int* sodaCount){

endProgram->assign("no");

endOrder->assign ("no");

while(!endProgram.compare("no")){

resetVariables(&totalBurger, &totalFry, &totalSoda, &total, &tax,&subtotal);

endOrder.assign("no"); //Necessary as if this is not there, the question won't take the second order onwards

while (endOrder.compare("no")==0)

{

printf("Enter 1 for Yum Yum Burger ");

printf("Enter 2 for Grease Yum Fries ");

printf("Enter 3 for Soda Yum ");

cin >> option;

if(option == 1)

getBurger(&totalBurger, &burgerCount);

else if (option == 2)

getFry(&totalFry, &fryCount);

else if (option == 3)

getSoda(&totalSoda, &sodaCount);

printf("Do you want to end your order? (Enter no to add more items:) ");

cin >> endOrder;

for(int i=0;i<endOrder.length();i++)

{

endOrder[i]=tolower(endOrder[i]);

}

}

calcTotal(&totalBurger, &totalFry, &totalSoda, &total, &subtotal, &tax);

printReceipt(total);

cout << "Do you want to end the program? (Enter no to process a new order) ";

cin >> endProgram;

for(int i=0;i<endProgram.length();i++){

endProgram[i]=tolower(endProgram[i]);

}

}

return 0; // no need for system(“pause”);

}