Thread: Please Help Me With This C Program!

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    23

    Please Help Me With This C Program!

    I want my program to give a similar output like this if total > 0:

    Welcome to the CIS 15AG Pizza Shack
    Pizza slice - $2.50 [y/n]? y
    Salad - $1.50 [y/n]? N
    Drink - $1.00 [y/n]? y
    Your total purchase: $3.50
    Tax: $0.32
    Total sale: $3.82
    Enter your payment: 5
    Thank you. Your change is $1.18
    Enjoy your meal


    else Welcome to the CIS 15AG Pizza Shack
    Pizza slice - $2.50 [y/n]? a
    You didn't answer y or n, assuming n
    Salad - $1.50 [y/n]? B
    You didn't answer y or n, assuming n
    Drink - $1.00 [y/n]? 7
    You didn't answer y or n, assuming n
    Guess you're not hungry





    This is the error message:

    "error C2660: 'change' : function does not take 1 arguments"

    change (total); <- underlined red in microsoft visual studio c++ 2010



    Code:
    #include <stdio.h>
    
    
    void menu1 (float *cost1);
    void change (float total, float pay, float chge);
    
    
    
    
    int main(void)
    
    {
        
        float total;
    
        printf ("hello to food store\n");
    
        menu1 (&total);
    
        change (total);
    
    
    }
    
    
    
    void menu1 (float *cost1)
    {
        char y;
        float c1 = 0;
        float tax;
        float total;
        char input;
    
        printf ( "Would you like to order a sandwhich ($2.00) ? [y/n]");
        scanf_s (" %c", &y);
    
        if (y == 'y' || y == 'Y')
        {
            
            c1 = c1 + 2;
        }
        else if ( y != 'n' || y != 'N')
        {
            printf (" you didn't order, ill take that as a no\n");
        }
    
         
        printf ( "Would you like to order a salad also ($1.00) ? [y/n]");
        scanf_s (" %c", &y);
    
        if (y == 'y' || y == 'Y')
        {
            
            c1 = c1 + 1;
        }
        else if ( y != 'n' || y != 'N')
        {
            printf (" you didn't order, ill take that as a no\n");
        }
    
    
    
         printf ( "Would you like to order a drink to go with that ($1.00) ? [y/n]");
        scanf_s (" %c", &y);
    
        if (y == 'y' || y == 'Y')
        {
            
            c1 = c1 + 1;
        }
        else if ( y != 'n' || y != 'N')
        {
            printf (" you didn't order, ill take that as a no\n");
        }
        
    
        tax = c1 * .0925;
        total = tax + c1;
    
        printf ("Your total purchase comes out to be: %.2f\n", c1);
        printf ("tax: %.2f\n", tax);
        printf ("Total sale: %.2f\n", total);
    
    
        *cost1 = total;
    }
    
    
    void change (float total, float pay, float chge)
    {
        
    
        if ( total > 0 )
        {
            printf ("Please enter your payment:");
            scanf_s ("%f", &pay);
            printf ("\n");
            
            chge = total - pay;
            
            printf (" You change is: %2.f", chge);
    
        }
        else
        { 
            printf ("Please order something or leave");
    
        }
    }

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    63
    The prototype you wrote for the function "change" is:
    Code:
     void change (float total, float pay, float chge);
    Yet, you use it like:

    Code:
     change (total);
    You need to either change your prototype or add two more arguments to your function call. In this case, I would change the prototype.

    Edit: My mistake on the part 'y' or 'n' part, you're correct.
    Last edited by failure67; 11-07-2011 at 12:53 AM.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    23
    Ah, thank you very helping a newbie out :}

    It is set up so that any answer other than "y" or "Y" will be taken as a "n"
    Last edited by Magic staple; 11-07-2011 at 12:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-16-2010, 10:17 AM
  2. Help converting array program to link list program
    By hsmith1976 in forum C++ Programming
    Replies: 0
    Last Post: 02-14-2010, 09:50 PM
  3. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  4. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  5. Replies: 18
    Last Post: 11-13-2006, 01:11 PM