Problem 85: Product

Create a structure named Product with following two fields-

1. name (string)
2. price (double)

Then create a function named printProductInfo() which takes a parameter of Product type and print the information of that Product. Finally, in main function create a variable of structure Product named myProduct and call the printProductInfo() function passing myProduct as the parameter.
code:

#include<stdio.h>
struct Product{
    char name[20];
    double price;
};

void printProductInfo(struct Product *pp){
    printf("Enter name: ");
    scanf(" %[^\n]",&pp->name);
    printf("Enter price: ");
    scanf(" %lf",&pp->price);
}
void printER(struct Product ppp){
    printf("name: %s\n",ppp.name);
    printf("Enter price: %.2lf\n",ppp.price);
}
int main()
{
struct Product p;

printProductInfo(&p);
printER(p);

    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *