C Programming Question?

– Create a menu as shown below.
– Ask the user to enter the movie code. Using if..else statement, identify the movie code.
If the code is not 1 or 2, display “Invalid Movie Code!” and terminate the system.
– Ask the user to enter number of tickets and day of the movie.
[Note: the day of movie has a range from 1-7. 1 as Monday, 2 as Tuesday, and so on]
– Then, by using switch..case statement, identify the day of movie.
If that is a weekday (1-5)
– 80% discount for Batman The Rise of the Dark Knight
– 70% discount for Avengers
If weekend (6-7)
– normal price
Else,
– Set price to 0
– By use another if..else statement, identify the price.
If price is 0, display “Invalid day!” and terminate the system.
Else, calculate the total price for the ticket purchase. Then, display the output as shown below.
#include
#include
#include
int main()
{
char movie[30];
int number_ticket, movie_day, code, day;
float movie_price, total_discount, discount, total_price;
printf(“——————————–…
printf(“\t\tMOVIE TITTLE\n”);
printf(“——————————–…
printf(” 1. Batman The Rise of the Dark Knight (RM10.00)\n”);
printf(” 2. Avengers (RM8.00)\n”);
printf(“——————————–…
printf(“\nEnter movie code :”);
gets(movie);
if(movie==1)
{
movie_price=10.00;
strcpy(movie,”Batman”);
printf(“Enter number of ticket :”);
scanf(“%d”, number_ticket);
printf(“Enter movie day (1-7) :”);
scanf(“%d”,movie_day);
switch(movie_day)
{
case 1:
discount=0.80;
total_discount=movie_price*discount;
break;
case 2:
discount=0.80;
total_discount=movie_price*discount;
break;
case 3:
discount=0.80;
total_discount=movie_price*discount;
break;
case 4:
discount=0.80;
total_discount=movie_price*discount;
break;
case 5:
discount=0.80;
total_discount=movie_price*discount;
break;
case 6:
total_discount=movie_price;
break;
case 7:
total_discount=movie_price;
break;
}
}
else if (code==2)
{
strcpy(movie,”Avengers”);
movie_price=8.00;
printf(“Enter number of ticket :”);
scanf(“%d”, number_ticket);
printf(“Enter movie day (1-7) :”);
scanf(“%d”,movie_day);
switch(day)
{
case 1:
discount=0.70;
total_discount=movie_price*discount;
break;
case 2:
discount=0.70;
total_discount=movie_price*discount;
break;
case 3:
discount=0.70;
total_discount=movie_price*discount;
break;
case 4:
discount=0.70;
total_discount=movie_price*discount;
break;
case 5:
discount=0.70;
total_discount=movie_price*discount;
break;
case 6:
total_discount=movie_price;
break;
case 7:
total_discount=movie_price;
break;
}
}
printf(“——————————–…
printf(“\t\tRECEIPT\n”);
printf(“——————————–…
total_price=total_discount*number_ticket…
printf(“\nMovie :%s”,movie);
printf(“\nNo. of Ticket :%d”,number_ticket);
printf(“\nTotal Price :%f”,total_price);
return 0;
}
this is my code, please help me modify them.
i don no how to modify.
Thank.

Both comments and pings are currently closed.

One Response to “C Programming Question?”

  1. Robert says:

    Was flying blind with your printf’s RE the … issue, but otherwise, try:
    #include
    #include
    #include
    int main()
    {
    char movie[30];
    int number_ticket=0, movie_day=0; //, code, day;
    float movie_price, total_discount, discount, total_price;
    printf(“—————————–n…
    printf(“ttMOVIE TITTLEn”);
    printf(“—————————–n…
    printf(” 1. Batman The Rise of the Dark Knight (RM10.00)n”);
    printf(” 2. Avengers (RM8.00)n”);
    printf(“—————————–n…
    printf(“nEnter movie code :”);
    gets(movie);
    if(movie[0]==’1′)
    {
    movie_price=10.00;
    strcpy(movie,”Batman”);
    printf(“Enter number of ticket :”);
    scanf(“%d”, &number_ticket);
    printf(“Enter movie day (1-7) :”);
    scanf(“%d”, &movie_day);
    switch(movie_day)
    {
    case 1:
    discount=0.80;
    total_discount=movie_price*discount;
    break;
    case 2:
    discount=0.80;
    total_discount=movie_price*discount;
    break;
    case 3:
    discount=0.80;
    total_discount=movie_price*discount;
    break;
    case 4:
    discount=0.80;
    total_discount=movie_price*discount;
    break;
    case 5:
    discount=0.80;
    total_discount=movie_price*discount;
    break;
    case 6:
    total_discount=movie_price;
    break;
    case 7:
    total_discount=movie_price;
    break;
    default:
    printf(“Invalid day coden”);
    break;
    }
    }
    else if (movie[0]==’2′)
    {
    strcpy(movie,”Avengers”);
    movie_price=8.00;
    printf(“Enter number of ticket :”);
    scanf(“%d”, &number_ticket);
    printf(“Enter movie day (1-7) :”);
    scanf(“%d”, &movie_day);
    switch(movie_day)
    {
    case 1:
    discount=0.70;
    total_discount=movie_price*discount;
    break;
    case 2:
    discount=0.70;
    total_discount=movie_price*discount;
    break;
    case 3:
    discount=0.70;
    total_discount=movie_price*discount;
    break;
    case 4:
    discount=0.70;
    total_discount=movie_price*discount;
    break;
    case 5:
    discount=0.70;
    total_discount=movie_price*discount;
    break;
    case 6:
    total_discount=movie_price;
    break;
    case 7:
    total_discount=movie_price;
    break;
    default:
    printf(“Invalid day coden”);
    break;
    }
    } else {
    printf(“Invalid movie coden”);
    return 0;
    }
    if (movie_day >= 1 && movie_day <= 7) { printf("-----------------------------n… printf("ttRECEIPTn"); printf("-----------------------------n… total_price=(movie_price*number_ticket) - total_discount; printf("nMovie :%s",movie); printf("nNo. of Ticket :%d",number_ticket); printf("nTotal Price :%f",total_price); } return 0; }

Powered by WordPress | Designed by: free css template | Thanks to hostgator coupon and web hosting reviews