Home > Back-end >  Of new C about the price of fruit from the question, don't know what wrong
Of new C about the price of fruit from the question, don't know what wrong

Time:10-02


Below is my code, the output only one Apple,


#include
Int main ()
{
Int m;
Char d;

Double g=0.0, sumprice=0.0, sumweight=0.0;
Double weight [4]={0.0};
While (the scanf (" % d ", & amp; M)!=(EOF)
{
for (int i=0; I & lt; M; I++)
{
Lf the scanf (" % c % \ n ", & amp; D, & amp; g);
If (d=='a')
{weight [0] +=g; }
If (d=='o')
{weight [1] +=g; }
If (d=='b')
{weight [2] +=g; }
If (d=='p')
{weight [3] +=g; }

}
For (int j=0; J & lt; 4. J++)
{
Sumweight +=weight [j];
}
Sumprice=weight weight [0] * 1.5 + 1.4 + [1] * weight [2] * 1.48 + weight [3] * 1.08;

Printf (" ");
Printf (" apple orange, banana pineapple sum \ n ");
Printf (" price ");
Printf (" % 7.2 lf ", weight [0] * 1.5);
Printf (" % 7.2 lf ", weight [1] * 1.4);
Printf (" % 7.2 lf ", weight [2] * 1.48);
Printf (" % 10.2 lf ", weight [3] * 1.08);
Printf (" % 7.2 lf sumprice);
printf("\n");

Printf (" weight ");
Printf (" % 7.2 lf ", weight [0]).
Printf (" % 7.2 lf ", weight [1]).
Printf (" % 7.2 lf ", weight [2]).
Printf (" % 10.2 lf ", weight [3]).
Printf (" % 7.2 lf ", sumweight);
printf("\n");
printf("\n");
For (int k=0; K & lt; 3; K++)
{
Weight [k]=0.0;
}
Sumweight=sumprice=0.0;
}

return 0;
}


  • Related