Hi everyone
This code works fine but the asterisks that print to represent the percentage is wrong. The example given was there was a total of 14 grades across the A-F range, but "A" had 1 and 1 should represent 4 stars one the chart.
Whats wrong????
#include <cstdlib>
#include <iostream>
#include <iomanip>
int a,Acent,b,Bcent,c,Ccent,Dcent,d,Ecent,e,Fcent,f,total,percent; //DECLARING
using namespace std;
int main(int argc, char *argv[])
{
cout<<"******************************************************"<<endl;
cout<<"This program will present the number of grades"<<endl; //INTRODUCTION
cout<<"you input for grades A-F and turn this information"<<endl; //TO
cout<<"in to a bar graph for ease."<<endl; //PROGRAM
cout<<"******************************************************"<<endl;
cout<<" "<<endl;
cout<<"Please enter how many grade A's"<<endl; cin>>a; //OBTAIN'S GRADE A
cout<<"Please enter how many grade B's"<<endl; cin>>b; // " " B
cout<<"Please enter how many grade C's"<<endl; cin>>c; //OBTAIN'S " C
cout<<"Please enter how many grade D's"<<endl; cin>>d; //" " D
cout<<"Please enter how many grade E's"<<endl; cin>>e; //OBTAIN'S " E
cout<<"Please enter how many grade F's"<<endl; cin>>f; //OBTAIN'S " F
total=a+b+c+d+e+f;
percent=100/total; //TOTALS THE GRADES
cout<<" "<<endl;
cout<<" TOTAL GRADES ENTERED - "<<total<<endl; //PRINTS TOTAL GRADES
Acent=percent*a/2; Bcent=percent*b/2; Ccent=percent*c/2; //calculates grade as percentage
Dcent=percent*d/2; Ecent=percent*e/2; Fcent=percent*f/2; //"
cout<<endl;
cout<<" 0 10 20 30 40 50 60 70 80 90 100"<<endl;
cout<<" | | | | | | | | | | |"<<endl;
cout<<" **************************************************"<<endl;
int array[6] = {Acent,Bcent,Ccent,Dcent,Ecent,Fcent}; //stores grades as percentage
char array2[6] = {'A','B','C','D','E','F'}; //stores letters a-f
for(int loopcounter=0; loopcounter<6; loopcounter++) //performs loop for generating asterisks
{ for(int asteriskcounter=0; asteriskcounter<6; asteriskcounter++)
{
cout<<" ";
}
for(int asteriskcounter=0; asteriskcounter<array[loopcounter]; asteriskcounter++)
{
cout<<"*";
}
cout<<setw(3)<<" GRADE "<<array2[loopcounter]<<endl; //prints grade after asterisks
cout<<endl;
}
system("PAUSE"); //pauses to display program
return EXIT_SUCCESS;
}