metalni

OOP Labs 1 Kupuvacka Kosnica

May 30th, 2020
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  typedef struct products {
  4.     char name[50];
  5.     float price;
  6.     float quantity;
  7. } products;
  8.  
  9.  
  10. float subTotal(float quantity, float price){
  11.     int subTotal;
  12.     subTotal = quantity*price;
  13.     return subTotal;
  14. }
  15.  
  16. void read(char *name, float *price, float *quantity){
  17.     scanf("%s %f %f", name, price, quantity);
  18. }
  19.  
  20.  
  21. void print(char *name, float *price, float *quantity, int i){
  22.     printf("%d. %s  %.2f x %.1f = %.2f\n", i, name, *price, *quantity, subTotal(*quantity,*price));
  23. }
  24.  
  25. int main(void){
  26.     products p[100];
  27.     int n;
  28.     float total=0.0;
  29.     scanf("%d", &n);
  30.    
  31.     for(int i=1; i<=n; i++){
  32.         read(p[i].name,&p[i].price,&p[i].quantity);
  33.     }
  34.  
  35.     for(int i=1; i<=n; i++){
  36.         total+=subTotal(p[i].quantity,p[i].price);
  37.         print(p[i].name,&p[i].price,&p[i].quantity,i);
  38.     }
  39.     printf("Total: %.2f", total);
  40. }
Add Comment
Please, Sign In to add comment