Discount price equation

CAN SOMEBODY PLEASE HELP ME FIGURE OUT THIS EQUATION ITS DRIVING ME INSANE.

I WANT TO BE ABLE TO FIND THE FINAL PRICE AFTER THE DISCOUNT.

SORRY FOR CAPS THIS IS REALLY GETTING TO ME.

THANKS GUYS
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
 	
	switch (choice)
	{
	case 1:
			system("cls");
			printf("\n\n");
			printf("*****************************************************\n");
			printf("**   Find Disclosed amount of your shopping bill   **\n");
			printf("*****************************************************\n");
			printf("\nPlease enter the item name: ");
			scanf("%s", &itemname);
			printf("\nPlease enter the price: ");
			scanf("%f", &price);
			printf("\nPlease enter the discount %%: ");
			scanf("%f", &discount);
			printf("\nWould you like to add any more items? Y/N: ");
			scanf("%s", &yn);
				
			
			if(yn == 'y')
			{
				printf("\nPlease enter the item name: ");
				scanf("%s", &itemname2);
				printf("\nPlease enter the price: ");
				scanf("%f", &price2);	
				
				total=price+price2;
				discounted=total*discount
				//cant get the equation//
				
				system("cls");	
			printf("*******************************\n");
			printf("** Your total price is: %.0f **\n", finalprice);
			printf("**  Press ENTER to continue  **\n");
			printf("*******************************\n");

				getch();
				system("cls");
				break;
			}
			else
			{
			
			finalprice=(discount*price)/100;
			
			printf("\nYour total price is: %.0f\nPress ENTER to continue", finalprice);
	
		 	getch();
			break;
			}
If they choose to add another item, you never calculate the final price and display it for them. Only when they choose not to add another item, meaning yn != 'y' which is basically your else statement, this happens:

1
2
3
finalprice=(discount*price)/100;
			
printf("\nYour total price is: %.0f\nPress ENTER to continue", finalprice);


Wouldnt you want to do that if they choose to add another item as well? The final price of both items in that case?

You do this in the if statement

1
2
3
4
printf("*******************************\n");
printf("** Your total price is: %.0f **\n", finalprice);
printf("**  Press ENTER to continue  **\n");
printf("*******************************\n");


You try and print out the final price, final price is not equal to anything. You never give final price a value, you only do it in the else statement.

Im also a bit confused of this finalprice=(discount*price)/100;

Why the divided by 100? isn't the final price just price*discount. If I have an item for 200 dollars, and the discount 50% off. Wouldnt it just be 200*0.5 = 100 dollars final price? The way you have it, if the item was 200 dollars and the discount was 50% off, the final price would be 10 dollars.
Last edited on
Yeah I haven't gotten to my else statement yet I just wanted to find it for my if
AND, the bit your confused about is the bit i am confused about. the whole post is asking for that exact equation haha
Topic archived. No new replies allowed.