how do i create a program so that when i put characters like A,B,C. And they have to calculate a value, like average. Ofcourse A,B,C are constants. And I want to use switch statements. But im totally lost
Bettie, I wrote a little program here that uses the constants A, B, & C set to some numbers, and then gives a menu for choosing what to do with those numbers. It uses a switch statement to handle the choice menu.
I gave up switches, cox it was too confusing. Tried doing it with "for" loop. But im not getting it write. The grade point average is the addition of all the four subject values. Only addition.
Hi Bettie,
I tried to understand your program, and I tried to solve your problem in my own way. Forgive me for any lackness, for I am still at the beginner stage.
One thing I still don't understand--> Why is that the point average calculated based on the addition only?
Here is my program:
#include<iostream.h>
main()
{
int i;
float total=0.00,p,g[5]={4.00,3.00,2.00,1.00,4.00};
char gr,gd[5]={'A','B','C','D','F'};
for(i=0;i<4;i++)
{
start:
cout<<"\n---------------------------------------------------";
cout<<"\nEnter grade for Subject "<<(i+1)<<"(A/B/C/D/F):";
cin>>gr;
if(gr==gd[0])p=g[0];
else if (gr==gd[1])p=g[1];
else if (gr==gd[2])p=g[2];
else if (gr==gd[3])p=g[3];
else if (gr==gd[4])p=g[4];
else
{
cout<<"Invalid!";
goto start;
}
cout<<"-->Point for Subject "<<(i+1)<<":"<<p;
total=total+p;
}
cout<<"\nTotal grades point for all subjects is "<<total;