So for the homework I need to compile and test a C++ program to present a user with a selection of movies to buy from. The user can choose from sci-fi, action, historical and terror movies.If the user chooses a sci-fi movie the cost is $10.50, action movies cost $12.00, historical movies cost $8.50 and terror movies cost $10.00. The user can choose as many movies as he/she wants to buy. When the user is done shopping your program must calculate the cost of shipping and the tax. The cost of shipping is calculated as follows:
$1.00 - $15.00 shipping is 10% of the total amount to pay
$16.00 - $30.00 shipping is 12% of the total amount to pay
$31.00 - $50.00 shipping is 15% of the total amount to pay
Free shipping if total amount to pay is > %50.00
Add the total amount to pay plus the shipping cost to calculate the tax. The tax rate is 0.080%. Calculate a final total by adding the tax. Display the total amount, the total cost of shipping, the tax and the final amount the user has to pay.
#inlcude <iostream>
using namespace std;
int main ()
{
char movie;//movie option
int selection;
double price;
double tax;
double totprice;
double shipping;
char answers;
}
cout<<"would you like to buy a movie? y for yes n for no" <<endl;
cin>>answers;
switch (answers==y)
cout<<"select movie" <<endl;
cout<<"movie1-terror" <<endl;
cout<<"movie2-scifi" <<endl;
cout<<"movie3-history" <<endl;
cout<<"movie4-action" <<endl;
cin>> selection;
#include<iostream>
usingnamespace std;
void price_total(string a, double price, double totprice) // creates a void function named price_total
{
if (a=="sci-fi")
{
price=price+10.50;
}
elseif(a=="action")
{
price=price+12.00;
}
elseif (a=="historical")
{
price=price+8.50;
}
elseif (a=="terror")
{
price=price+10.00;
}
else
{
cout<<"Invalid entry"<<endl;
}
totprice=price;
}
int main()
{
double tax;
double shipprice;
double totprice;
double price;
char answer_1;
char answer_2;
string answer_movie;
cout<<"Would you like to buy a movie? 'Y' 'N'"<<endl;
cin>>answer_1;
if (answer_1=='y' || answer_1=='Y') // || means 'OR'
{
movie_ans:
cout<<"sci-fi"<<endl;
cout<<"action"<<endl;
cout<<"historical"<<endl;
cout<<"terror"<<endl;
cin>>answer_movie;
price_total(answer_movie, price, totprice);
cout<<"Would you like to buy another movie? 'Y' or 'N'";
cin>>answer_1;
if (answer_1=='y' || answer_1=='Y')
{
goto movie_ans;
}
elseif (answer_1=='n' || answer_1=='N')
{
if(totprice>=1.00 && totprice<=15.00)
{
shipprice=price/10;
}
elseif (totprice>=16 && totprice<=30)
{
shipprice=totprice*(12/100);
}
elseif (totprice>=31 && totprice<=50)
{
shipprice=price*(15/100);
}
elseif(totprice>50)
{
shipprice=price/2;
}
}
}
tax=(totprice+shipprice)*(80/1000);
cout<<"Tax:"<<tax<<endl;
cout<<"Start Price:"<<totprice<<endl;
cout<<"Shipping price:"<<shipprice<<endl;
cout<<"Total Price:"<<sipprice+tax+totprice<<endl;
}
I hope you understood my code.
More for functions:https://www.google.com.cy/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CC8QFjAB&url=http%3A%2F%2Fwww.cplusplus.com%2Freference%2Ffunctional%2Ffunction%2F&ei=nzkUU5L-OcKw7Aa8mYH4DQ&usg=AFQjCNFrBjqFoTvbIuDfgx0vgYVNbq72mQ&bvm=bv.61965928,d.ZGU
More for goto statement:https://www.google.com.cy/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&ved=0CDAQFjAC&url=http%3A%2F%2Fwww.tutorialspoint.com%2Fcplusplus%2Fcpp_goto_statement.htm&ei=wTkUU5_6IInT7AaJ84HYBg&usg=AFQjCNH8rDyuVrzsQ1GCXuB7gzmj9GexXA&bvm=bv.61965928,d.ZGU
Sometimes goto is the best way to solve your problems. I use it for shortening my code. If it were useless then it wouldn't exist!Also if you explain me why you've been taught to do not use goto it would be very helpful.
Last thing i have to say; what does FWIW mean?
It was commonly used before the advent of structured programming. There may be a few situations where it still may be useful, but it can make it hard to follow and debug programs when the code jumps around ("spaghetti code").
Why did you use goto in your program? Seems like a while/do..while structure could have been used?
I use goto for making my code smaller. Also 2 years ago, when i started learning Small Basic, it was a bit easier for me. Now i found that it can be used and in C++!
I started Small basic when i was 9.
*When i said Now i didn't mean right now i meant the whole time I've been learning C++(2 months and a half). I used Now because before that statement i reffered to a past action.
Explained because i don't want you to be confused.
*You hear i meant in plural.
Sometimes goto is the best way to solve your problems. I use it for shortening my code. If it were useless then it wouldn't exist!Also if you explain me why you've been taught to do not use goto it would be very helpful. And be thankful that i have done you're homework for you.
Last thing i have to say; what does FWIW mean?
FWIW - for what it's worth.
You haven't done my homework for me, I'm not the OP (original poster). :)