0

Code:

#include <stdio.h>
float getUserDetail(char*, float*);
float getDiscount(char, float, float, float*);
float getDetails(char*, float*, float*);
float FPrint(char*, float*, float*, float*);

int main()
{
    char name, CH, Std, movie;
    float age, RM, Disc, seat, Time;
    printf("\t\t\t\tWELCOME TO UniMAP CINEMA!!!");
    do      
    {
        getUserDetail(&name, &age);
        getDiscount(Std, age, RM, &Disc);
        getDetails(&movie, &seat, &Time);
        printf("\nDo you like to continue? If yes, press 'Y':");
        scanf("%s",&CH);
    }
    while(CH=='Y'||CH=='y');
    FPrint(&movie, &seat, &Time, &Disc);
    printf("\n\t\t\tThank you");
    return 0;
}
float getUserDetail(char*name, float*age)
{
    printf("\nName: ");
    scanf("%s", name);
    printf("Age: ");
    scanf("%f",age);
    return (*age);
}
float getDiscount(char Std,float age, float RM, float*Disc)
{
    RM == 15;
    if (age < 13){
        *Disc == ((30/100)*RM); 
        return (*Disc); }
    else if (age < 19){
        printf("Are you a student?(Y/N):");
        scanf("%s", &Std);
            {
            if(Std == 'Y'|| Std == 'y'){
                *Disc == ((50/100)*RM);
                return (*Disc); }
            else
                *Disc == RM;
                return (*Disc); }}
    else
        *Disc == RM;
        return (*Disc);
}
float getDetails(char*movie, float*seat, float*Time)
{
    printf("Name of the movie: ");
    scanf("%s", &movie);
    printf("Number of the seat: ");
    scanf("%f", &seat); 
    printf("Time of the movie: ");
    scanf("%f", &Time);
}
float FPrint(char*movie, float*seat, float*Time, float*Disc)
{
    printf("\n\t\t\tBooking Successful");
    printf("\n\t\tMovie Name:%s", &movie);
    printf("\n\t\tSeat Number:%f", &seat);
    printf("\n\t\tTime:%f", &Time);
    printf("\n\t\tDiscounted Price:RM%s", &Disc);
}

Output:

Name: kaus
Age: 21
Name of the movie: qwerty
Number of the seat: 21
Time of the movie: 2.15

Do you like to continue? If yes, press 'Y':n

                        Booking Successful
                Movie Name:§■e
                Seat Number:0.000000
                Time:0.000000
                Discounted Price:RM
■e
                        Thank you
--------------------------------
Process exited after 14.19 seconds with return value 0
Press any key to continue . . .

If I put the '*' instead of '&' and the printf part I get this output:

Name: kaus
Age: 21
Name of the movie: qwerty
Number of the seat: 21
Time of the movie: 2.15

Do you like to continue? If yes, press 'Y':n

                        Booking Successful
                Movie Name:(null)
                Seat Number:0.000000
                Time:0.000000
                Discounted Price:RM(null)
                        Thank you
--------------------------------
Process exited after 12.51 seconds with return value 0
Press any key to continue . . .

What do I do? and please do forgive me for any silly mistakes I might have made.Thank You.

Tried using '*' and '&' but not getting the correct output. Still rusty on the topic of pointers I want it to print out the movie name: time: seat no.: price:

  • 2
    The compiler gives about a dozen warnings from this code. You should work through them first. For example at `RM == 15;` – Weather Vane Nov 11 '22 at 17:39
  • 1
    There will be unwarned problems too such as the integer division in `*Disc == ((50/100)*RM);` which will always be `0` *as well as* the `==` error. – Weather Vane Nov 11 '22 at 17:42
  • 1
    Before anything, you need to read your [C textbook's](https://stackoverflow.com/q/562303/2505965) chapter on [*strings*](https://en.cppreference.com/w/c/string/byte). Then move on and read the chapter that covers [*pointers*](https://en.cppreference.com/w/c/language/pointer). – Oka Nov 11 '22 at 17:48
  • How do you expect to store more than one character in a `char`? Sorry. but this code has so many problems, it's totally broken. Throw it away and start from scratch once you have learned some basics about strings and pointers. – Jabberwocky Nov 11 '22 at 18:27
  • If you want to get a head start, forget `scanf` exists entirely for the moment. Focus on learning how [`fgets`](https://en.cppreference.com/w/c/io/fgets) works, which will naturally teach you about strings. With that, use [`strtol`](https://en.cppreference.com/w/c/string/byte/strtol) and [`strtod`](https://en.cppreference.com/w/c/string/byte/strtof) to parse numbers from strings. – Oka Nov 11 '22 at 18:48

0 Answers0