Hello there,ihave given the assigment to make the c program to print the asterisks to represent the grades..

My question is , why the asteriks does not appear ? I think i got problem at the looping for asterisk..
actually my output should be like this :

the graph such that 50 asterisks correspond to 100 percent (each one corresponds to 2 percent), the horizontal axis goes from 0 to 100 percent with 10 percent in each increment, and each line for data is labeled with letter grade

0 10 20 30 40 50 60 70 80 90 100%
| | | | | | | | | | |
***************************************************
**** A
************** B
********************* C
******* D
**** F

This is my code..

#include <stdio.h>
#include <conio.h>

int main()
{

double Acent,Bcent,Ccent,Dcent,Fcent ;
int a,b,c,d,f,total ;
printf ("Please enter how many grade A's\n");
scanf  ("%d", &a) ;
printf ("Please enter how many grade B's\n");
scanf  ("%d", &b) ;
printf ("Please enter how many grade C's\n");
scanf  ("%d", &c)  ;
printf ("Please enter how many grade D's\n");
scanf  ("%d", &d) ;
printf ("Please enter how many grade F's\n");
scanf  ("%d", &f) ;
total  =a+b+c+d+f ;

printf (" \n");
printf (" TOTAL GRADES ENTERED = %d\n", total);

Acent  = a / total * 100  ;
Bcent = b /  total * 100  ;
Ccent = c   / total * 100 ;
Dcent = d  / total * 100  ;
Fcent = f / total * 100   ;


printf ("\n"); //End Line.
//Scale to assist user
printf ("0   10   20   30   40   50   60   70   80   90  100\n");
printf ("|    |    |    |    |    |    |    |    |    |    |\n");
printf ("***************************************************\n");

int loopcounter ;
int asteriskcounter ;

double array[5] = {Acent,Bcent,Ccent,Dcent,Fcent}; //stores grades as percentage
char array2[5]  = {'A','B','C','D','F'}; //stores letters a-f

for(loopcounter=0; loopcounter<5; loopcounter++) // loop for each grade
{
printf (" ");


for(asteriskcounter=0; asteriskcounter<array[loopcounter]/2; asteriskcounter++)// loop to output each asterisk

{
printf ("*");

}
printf ("  %c\n", array2[loopcounter]); // print the grade after the asterisks
printf ("\n");

}
getch ();
return 0 ;
}

Edited 4 Years Ago by naz1234: n/a

hmm sory what do you mean by code that isn't formatted.?

There's a link posted on WaitP's post

Anyway check the Values of Acent to Fcent...did you notice that their output is 0

Sorry for my code that does not following the format..
Where do you notice that the output is zero? I try looking at my code but cant figure it out.
I'm very new to C programming so sorry... if i come
across as stupid!

Sorry for my code that does not following the format..
Where do you notice that the output is zero? I try looking at my code but cant figure it out.
I'm very new to C programming so sorry... if i come
across as stupid!

Acent  = a / total * 100  ;

right after this line printout Acent's value

Oh my god..thank you..yes you are right..the value is 0.0000..
what am I doing wrong? should I change the double to the float or somthing ?

Thanks you very much :) for your suggestion..
By the way I try to change the equation :

Acent = (a*100)/total  ;
Bcent = (b*100)/total  ;
Ccent = (c*100)/total ;
Dcent = (d*100)/total  ;
Fcent = (f*100)/total   ;
This question has already been answered. Start a new discussion instead.