Click here to Skip to main content
16,015,755 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Write a C program to implement a basic billing system
that accepts product code and price for 5 products and
at the end, display the total price.
Hint: Store the product code and price in a structure.
Accept the details for five products through a structure
array and then proceed further.
Note that input values must be given as integers. Failing
this, the evaluation will terminate and will not proceed
further.
Input Format
5 lines of input, each line having 2 integers,
representing product code and price respectively.
Output Format
Single integer value representing total price
Sample Input
10125
102 30


What I have tried:

1
#include (stdio.h›
2E struct Productf
3
int product
code;
4
int product price;
S
6E mainOf
7
# Declare the variable
8
int a = B;
int i;
18
struct Product prod[5];
11B for(¡=8; i‹5; i++)
12
I Read the variable from S
13
scanf("\d «d", &prod[i].prod
14
a
= a+prod[i].product pride;
)
the
variable to STD
printf("yd", a);
Note you need to explicit
otherise your
solution will
18
19
28
21
PHPA
Posted
Updated 20-Jan-22 0:20am

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Your attempt didn't produce valid C code. I'm giving you, as a hint, the struct and array definitions:
C
enum
{
  PRODUCTS = 5,
};

typedef struct 
{
  int code;
  int price;
} Product;


Product prod[PRODUCTS];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900