what am i missing really lost in programming please help

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;



Last edited on
This might be the answer you ask for?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>

using namespace 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;

    }
    else if(a=="action")
    {
        price=price+12.00;
    }
    else if (a=="historical")
    {
        price=price+8.50;
    }
    else if (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;
        }

        else if  (answer_1=='n' || answer_1=='N')
        {
            if(totprice>=1.00 && totprice<=15.00)
            {
                shipprice=price/10;
            }
            else if (totprice>=16 && totprice<=30)
            {
                shipprice=totprice*(12/100);
            }
            else if (totprice>=31 && totprice<=50)
            {
                shipprice=price*(15/100);
            }
            else if(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
Last edited on
FWIW, I've been taught to avoid using goto statements in new programs. I don't think I'd want to turn in homework using that technique.
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?
Last edited on
I think people dislike goto because you can jump all over the place making the code hard to follow.
There's discussion on goto in this forum - a search brings up a bunch of threads.

http://www.cplusplus.com/forum/beginner/121946/
http://www.cplusplus.com/forum/general/77266/
http://www.cplusplus.com/forum/general/7608/
http://www.cplusplus.com/forum/general/29190/
http://www.cplusplus.com/forum/beginner/118361/

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?
Last edited on

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.

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;

	do
	{
		cin>>answer_1;

		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'";

	} while (answer_1=='y' || answer_1=='Y');

	if(totprice>=1.00 && totprice<=15.00)
	{
		shipprice=price/10;
	}
	else if (totprice>=16 && totprice<=30)
	{
		shipprice=totprice*(12/100);
	}
	else if (totprice>=31 && totprice<=50)
	{
		shipprice=price*(15/100);
	}
	else if(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:"<<shipprice+tax+totprice<<endl;
}

I don't think using a loop made it much bigger in this case. To me this is much easier to follow (maybe because I'm not used to using goto?).
Last edited on
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). :)
Last edited on
Topic archived. No new replies allowed.