Question

C++; functions declared in main, but defined out side of main You've just feasted on a...

C++; functions declared in main, but defined out side of main

You've just feasted on a truly delicious meal of spam and eggs and a couple of pints of Davey Jones’s ale. Unfortunately, you are on board a pirate ship so payment is a little tricky. You need to calculate not only the cost of your meal, but also the governor’s tax, the captain’s tax, and a tip for the ship mates serving you as well as a sundry of other items. You also must pay in silver ducats, not American dollars. If you don’t pay, you’ll be walking the plank.

Step 1. Input

  • Ask the user for the cost of their food.
  • Ask the user how much ale they drank (number of pints).
  • Validate the entries to be numeric and good (greater than 0).

Step 2. Cost of eating on a pirate ship

  • A pint of ale is USD$4.50.
  • Taxes:
    • Governor’s tax is 6% on both the meal and the ale. This keeps the king’s army from harassing your ship too much.
    • Captain’s tax is 8% on the ale only. He’s a pirate and the captain. Pay it and consider buying him a pint, too, just to be on the safe side.
    • Ship mate’s tip for swabbing your mess off the deck is 10% on the food only. (No respectable pirate would spill good ale.)
    • Pirate’s retirement fund is ½% of the pre-tax total.
  • Silver prices vary but we’ll assume USD$24 per ounce. You have a bag full of ¼-ounce ducats (so each is worth USD$6) that cannot be divided, so once you have the bill in dollars you must compute the number of coins to leave and round up to a whole number.

Step 3. Output

  • Calculate and output as an itemized bill:
    • Total pre-tax bill (food + ale consumed) in dollars.
    • Governor’s tax in dollars.
    • Captain’s tax in dollars.
    • Ship mate’s tip in dollars.
    • Retirement fund in dollars.
    • Total bill in dollars.
    • Total number of silver coins to leave.

For example, if the meal was $13.75 and 5 pints of ale were consumed, your output should look something like this:

---------------------------------

          The Galley of

The Feared Raider of the Cuyahoga

---------------------------------

Meal                      $ 13.75

Ale                       $ 22.50

                           ------

Subtotal                  $ 36.25

Gov tax                  $ 2.18

Capt tax                  $ 1.80

Mate tip                  $ 1.38

Retirement fund           $   .18

                           ------

Total                     $ 41.79

Payment                  7 ducats

Step 4. Repeat

This program must repeat (up to 10 times), taking new input for new entries. Therefore, after each output has been displayed your program will start again by asking for another entry. If the number of times repeated is more than 10, display a message and promptly exit. Each time before asking for new input again, the screen must scroll (roll off). You can do this in a variety of ways, however, don’t forget to pause the screen so the user can review the report prior to starting again. Leave an option for the user to exit (no more entries). Do this by using a sentinel.

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

/******************************************************************************

This is c++ code of the program

*******************************************************************************/

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
float food_cost;
char ch;
int num_ale,n=2;
while(n){
cout<<"Enter the cost of meal in (Dollars)\n";
cin>>food_cost;
cout<<"Enter the no. of ale your have\n";
cin>>num_ale;
if(food_cost>0 && num_ale>0){
cout<<"-------------------------------\n";
cout<<" The Gallery of\n The Featured Raider of the Cuyhoga\n";
cout<<"-------------------------------\n";
cout<<"Meal $ "<<food_cost<<endl;
float ale_cost=num_ale*4.50;
cout<<"Ale $ "<<ale_cost<<endl;
cout<<" --------"<<endl;
float subtotal=food_cost+ale_cost;
cout<<"Subtotal $"<<round(subtotal*100)/100<<endl;
float gov=(subtotal*6)/100;
cout<<"Gov tax $"<<round(gov*100)/100<<endl;
float capt=(ale_cost*8)/100;
cout<<"Capt tax $"<<round(capt*100)/100<<endl;
float tip=(food_cost*10)/100;
cout<<"Mate tip $"<<round(tip*100)/100<<endl;
float fund=(subtotal*0.5)/100;
cout<<"Retirement fund $"<<round(fund*100)/100<<endl;
cout<<" --------"<<endl;
float total=subtotal+gov+capt+tip+fund;
cout<<"Total $"<<round(total*100)/100<<endl;
cout<<"Payment $"<<round(total/6)<<" ducats"<<endl;
cin.get(ch); //You can also use system("pause") but it is platform dependent
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
char ans='y';
cout<<"Enter again (y/n)"<<endl;
cin>>ans;
if(ans=='y'){
n--;
}else{
n=0;
}
  
}
else{
cout<<"Invalid Input\n";
}
}
cout<<"Program Terminated\n";
  

return 0;
}

SAMPLE OUTPUT:-

Add a comment
Know the answer?
Add Answer to:
C++; functions declared in main, but defined out side of main You've just feasted on a...
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
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
Active Questions
ADVERTISEMENT