#include %26lt;stdio.h%26gt;
main(void)
{
int i, j;
float price[10];
printf(" Please key in an initial price in RM: ");
scanf("%f", %26amp;price[0] );
printf(" \n\t\t\tMyZan Departmental Store\n ");
printf(" \t\t\t ");
for(j=1;j%26lt;=24;j++)
{
printf("-");
}
printf("\n\n");
printf("%30s%25s", "Price Before", "Price After");
printf("\n%28s%28s", "Discount", "20 % Discount");
printf("\n%26s%25s", "(RM)", "(RM)");
printf("\n");
for (i=0; i%26lt;=9; i++)
{
price[i+1] = price[i] *0.8;
printf( "\n%26.2f",price[i] );
printf( "\t%19.2f", price[i+1] );
price[i+1]=price[i]+10;
}
}
C program, whats the problem with this? pls check it out..?
Without knowing exactly what's going wrong, the project description seems to indicate that this line:
price[i+1]=price[i]+10;
should use price[i+1] as its source, rather than price[i].
The loop should also run while i%26lt;9, not %26lt;=.
Hope that helps.
Reply:%26gt; float price[10];
%26gt; for (i=0; i%26lt;=9; i++)
%26gt; price[i+1] = price[i] *0.8;
You can't write to price[10].
I don't fully understand why you're writing the discount price into the next entry in the array at all though, so I don't know how to recommend what to change.
edit: I'd suggest not storing either the "next" value or the discount value in an array. Conceptually much simpler, and you overwrite the % immediately anyway.
pokemon cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment