I dont know how to pass a value from the function total(); to main() ...i want get the value of the prod and assign its value to bill...But this code i have will only redo the function total() ...Anyone can help please?.

#include <stdio.h>
#include <conio.h>

int header();
int choices(int);
int total(int);


int main()
{
    int bill=0,cash;
    int choice;
    
    header();
    printf("What do you want to buy: ");
    scanf("%d",&choice);
    
    choices(choice);
    
    bill=total(cash);
    
    
    printf("\nTendered amount: ");
    scanf("%d",&cash);
    
    printf("\nYour change: %d",cash-bill);
    
    getchar(); 
    getchar();
}
       
    

int header()
{
    
    printf("Welcome to my store!\n\n");
    printf("  Items available\n\n");
    printf("[1] Paper \tP35\n[2] Pen   \tP10\n[3] Notebook\tP15\n\n");
    
}


int choices(int c)
{
    int price;
    if(c==1)
    {
            price = 35;
            
                   
            total(price);
                  
                   
    }
    if(c==2)
    {
            price = 10;
   
            total(price);
                   
                
    }
    if(c==3)
    {
            price = 15;
  
            total(price);
                   
                  
    }
    if(c>3)
    printf("Error!");               
}  


int total(int price2)
{
    int prod,qnt,t;
    
    printf("\nQuantity: ");
    scanf("%d",&qnt);
    
    prod = qnt*price2;
    printf("\nBill is: %d",prod);
    
    t=prod;
    return t;
}

What you would need to do is have Choices() return the value from Total(). Then set bill to the return value of Choices(). Like so,

int main()
{
    int bill = 0;

    int choice;
    
    header();
    printf("What do you want to buy: ");
    scanf("%d",&choice);
    
    bill = choices(choice);
    
    //bill = total(cash);
    
    printf("\nTendered amount: ");
    scanf("%d",&cash);
    
    printf("\nYour change: %d",cash-bill);
    
    getchar(); 
    getchar();
}

int choices(int c)
{
    int price;
    if(c==1)
    {
            price = 35;
            return total(price);
    }
    if(c==2)
    {
            price = 10;
            return total(price);
    }
    if(c==3)
    {
            price = 15;
            return total(price);
    }
    if(c>3)
    printf("Error!");               
    return 0;
}

int total(int price2)
{
    int prod,qnt,t;
    
    printf("\nQuantity: ");
    scanf("%d",&qnt);
    
    prod = qnt*price2;
    printf("\nBill is: %d",prod);
    
    return prod;
    //t=prod;
    //return t;
}

It worked...Thank you so much for your help...
OMG i need to learn that...It's very confusing...

Marked as Solved...

Happy to help.

You'll get your head around soon enough. You'll be returning values all over the place if you keep programming :)

Yea i've tried passing values from my other programs...
But i did not do something like this... That's what really confuse me when i try to pass a value from a function to main...

This question has already been answered. Start a new discussion instead.