Pls help me..asap

Discussion in 'C' started by farahlyna, Aug 28, 2010.

  1. farahlyna

    farahlyna New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    In C a structure is passed to a function by value. This means that the structure valued is copied for processing in the body of the function. Therefore any changes made to the value by the function would not give any effect on the value of the structure Any idea for me to insert the function void for this program..
    Code:
    
    #include
    
    struct book{
    
    char title[80];
    int bar_code;
    float price;
    
    };
    struct book BOOK;
    float price2,discount;
    void main(){
    
    struct book *ptr;
    ptr = &BOOK;
    
    clrscr();
    printf("Title:");
    /**scanf("%s", &ptr->title);**/
    gets(ptr->title);
    printf("bar code:");
    scanf("%d", &ptr->bar_code);
    printf("Price:");
    scanf("%f", &ptr->price);
    
    price2 = ptr->price;
    if (price2>=100) {
    discount =price2-(price2*0.10);
    
    printf("discount price:%.2f",discount);
        }
    
    printf("-----------------------\n");
    printf("%s\n", ptr->title);
    printf("%d\n",(*ptr).bar_code);
    printf("Before Discount:%.2f\n", ptr->price);
    printf("After Discount:%.2f\n", discount) ;
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice