Some mistake in my code ?

Question 1 (15 marks)

Build a “Point of Sales” C program for BIGSALES mall that fulfil the below requirements:

1. Print a unique greeting message and logo for your point of sales program. And, prompt the user to enter the year of birth.

2. After that, the program should allow user to choose from the 4 options below:

Option 1: Enter products purchased
Option 2: Enter parking hours
Option 3: Calculate and print the total bill
Option 4: Exit

Option 1 requirements:
The program should read in an indefinite series of products (product code and quantity) purchased by customer. Same product code can be entered more than once.

Given that the retail prices of the products sold by BIGSALES mall are limited to four codes and as listed below:

Product code Retail price (RM)
1 45.20
2 14.50
3 3.45
4 7.80


Option 2 requirements:
The program should read in the customer’s total parking hours. The hours can be in fraction (e.g. 3.15 hours).

Given the calculation of parking fee as below:

Parking fees calculation
RM2.00 minimum fee to park for up to three hours and an additional RM0.50 per hour for each hour or part thereof over three hours. The maximum charge for any given 24-hour period is RM10.00. No car parks for longer than 24 hours should be calculated.


Tips: You can use the C standard function ceil(x) in the math.h library to round up the hours.


Option 3 requirements:
Your program should calculate and display the total bill in a neat format by listing out:
• The total bill and quantity sold for each product code
• The subtotal of the bill
• The 6% government tax of the subtotal
• The total parking hours and parking fees
• The grand total. If the customer is a senior citizen (60 years old and above), he/she shall be given a 10% discount on the grand total. (Assume the current year is 2013).

Note: Your program should use a switch statement to determine the option chosen by the user. Your program should not exit if user does not choose option 4.


You are encouraged to improve your code structure by using any additional controls, validations, or messages which you think are appropriate.

You are allowed to have variances of display design, arrangement or format, as long as it fulfilled the requirement stated above.




~ END OF PAPER ~



**********************************************************
This is my code but I got an error can anyone help me to check ? tq

*************************************************************


#include <stdio.h>

int main( void )
{
printf("Welcome to\nBIGSALE mall!\n");

int year;
printf("Please enter your year of birth \n");
scanf("%d",&year);

int productcode, quantity_sold;
int productcode1, quantity_sold1, Total1, Product_unit_price1 = 45.20;
int productcode2, quantity_sold2, Total2, Product_unit_price2 = 14.50;
int productcode3, quantity_sold3, Total3, Product_unit_price3 = 3.45;
int productcode4, quantity_sold4, Total4, Product_unit_price4 = 7.80;

printf("Enter product code(enter 1 to 4)(enter -1 to exit) \n");
scanf("%d", &productcode);

while(productcode != -1)
{
if(productcode == 1)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold1);

}
else if (productcode == 2)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold2);

}
else if (productcode == 3)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold3);

}
else if (productcode == 4)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold4);

}
else
{
printf("The code does not exist. Please try again!");
}

}

//printf("Enter quantity sold \n");
//scanf("%d", &Quantity_Sold);

return 0;
}

#include <stdio.h>

int main( void )
{
float parkinghours;
float parkingcharge;

printf( "Enter total parking hours!\n" );
scanf( "%f", &parkinghours );

if(parkinghours <=3){
parkingcharge = 2.00;
}

else if(parkinghours >=3){
parkingcharge = 2.00 + 0.50*

printf ( "Total parking hour is %.2f\n", parkinghours);

return 0;

}
Please use code tags in future!

And be more specific about what errors you are having! I have added in some comments where you have problems.

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
#include <stdio.h>

int main( void )
{
printf("Welcome to\nBIGSALE mall!\n");

int year;
printf("Please enter your year of birth \n");
scanf("%d",&year);

int productcode, quantity_sold;
int productcode1, quantity_sold1, Total1, Product_unit_price1 = 45.20;
int productcode2, quantity_sold2, Total2, Product_unit_price2 = 14.50;
int productcode3, quantity_sold3, Total3, Product_unit_price3 = 3.45;
int productcode4, quantity_sold4, Total4, Product_unit_price4 = 7.80;

printf("Enter product code(enter 1 to 4)(enter -1 to exit) \n");
scanf("%d", &productcode);

while(productcode != -1) //Once started, this loop will never finish. Nothing within the loop modifies the value of productcode. 
{
if(productcode == 1)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold1);

}
else if (productcode == 2)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold2);

}
else if (productcode == 3)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold3);

}
else if (productcode == 4)
{
printf("Please enter quantity purchased");
scanf("%d", &quantity_sold4);

}
else
{
printf("The code does not exist. Please try again!");
}

}

//printf("Enter quantity sold \n");
//scanf("%d", &Quantity_Sold);

return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>

int main( void )
{
float parkinghours;
float parkingcharge;

printf( "Enter total parking hours!\n" );
scanf( "%f", &parkinghours );

if(parkinghours <=3){
parkingcharge = 2.00;
}

else if(parkinghours >=3){
parkingcharge = 2.00 + 0.50* //This is just left open and is going to cause an error 
}//You also need to add a closing brace here. 

printf ( "Total parking hour is %.2f\n", parkinghours);

return 0;

}
Last edited on
Topic archived. No new replies allowed.