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
Step 2. Cost of eating on a pirate ship
Step 3. Output
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.
/******************************************************************************
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:-
C++; functions declared in main, but defined out side of main You've just feasted on a...