Home > Back-end >  C language array to solve the problem, just learning
C language array to solve the problem, just learning

Time:03-20

Product sales records, array, array, array, urgent urgent, strives for the big help, please

CodePudding user response:

Your code? See only a compiler error, didn't see the code, this how can I help? You mean according to the requirements of you to write a? !

CodePudding user response:

Reference:
//product sales records including product code name information such as unit price amount 
//1) writing input function input 10 product sales record as above information
//2) write the sum function calculation amount=number of unit price *
//3) write sort function according to the amount of money from big to small order

# include
10//# define PRODUCTS according to the topic request 10 PRODUCTS

Void input ();
Float the sum (float a, int n);
Void the sort ();


Typedef struct {//custom structure type
Int code;
Char name [21].
Float price;
Int quantity;
} the PRODUCT;

The PRODUCT products [products];//define array of 10 product record

Void main ()
{
The input ();//enter
Sort ();//sorting, from big to small
for(int i=0; I & lt; PRODUCTS; I++) {//print
Printf (" code=% d | quantity=% d | price.=% 2 f | | name=% s sum.=% 2 f \ n ",
Products [I] code, products [I]. Quantity, products [I] price, products [I]. Name,
The sum (products [I]. Price, products [I] quantity));
}

}

Void input () {
Printf (" Enter example: code, quantity, price, name (30) \ n ");
for(int i=0; I & lt; PRODUCTS; I++) {
The scanf (" % d % d % f, % s ", & amp; Products [I] code, & amp; Products [I]. Quantity,
& Products [I]. Price, products [I] name);
}
}

Float the sum (float a, int n)
{
Return a * n.
}

Void the sort () {
The PRODUCT temp.
for (int i=0; I & lt; PRODUCTS - 1; I++) {
For (int k=0; k If ((products [k]. Price * products [k]. Quantity) & lt;
(products [k + 1] price * products [k + 1] quantity))
{
Temp=products [k].
Products [k]=products [k + 1);
Products [k + 1)=temp;
}
}
}
}


//Enter example: code, quantity, price, name (30)
//11 20 aa
2.00//22 30 1.00 bb
//33 10 3.00 cc
//code=11 | quantity=20 | | price=2.00 name=aa | sum=40.00
//code=22 | | quantity=30 price=1.00 | | name=bb sum=30.00
//code=33 | | quantity=10 price=3.00 | name=cc | sum=30.00
//please press any key to continue...
  • Related