You mention that you are a beginner, so I will try to avoid calling out every little problem, but try to address what I think you are asking to fix.
1 2 3 4 5 6 7
|
double fomula() // foumula for the calculation of the GPA
{
gpa = ((gp1*ch1)+(gp2*ch2)+(gp3+ch3)+(gp4*ch4))/((ch1+ch2+ch3+ch4));
double GPA = (double)gpa;
return gpa;
}
| |
|
The equation would seem to be doing integer division, which you may not want. The main problem here may be you are casting the integer "gpa" to a double "GPA", but then returning the integer when the function should return a double. It can be very confusing to have such similarly named variables.
Consider setting rules for how you format your code (or more preferably asking your instructor about formatting) and strictly adhering to them. For example foumula() (sic) should be capitalized as it is a function. This may not be necessary but is generally considered good practice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void Case() // SELETION OF CLASS
{
switch (gpa)
for (; gpa >= 4; ++gpa)
{
case 4:
cout << "4.0: \t 1st class " << endl;
break;
case 3:
cout << "3.0: \t 2nd class " << endl;
break;
case 2:
cout << "2.0: \t 3rd class " << endl;
break;
case 1:
cout << "1.0: \t pass " << endl;
break;
}
}
| |
|
This bit confused me a little, as I was a little unsure what you were trying to do. You are using a switch statement and for loop, the placement of the curly braces defines the switch statement where the body of the for loop would be expected, and the structure of the for loop confused me, as it is testing if "gpa" is greater than or equal to 4 and incrementing gpa after each iteration, but the body of the loop is the body of the switch statement.
...
On further thought, it appears that you want to output the gpa for each class, if so you should probably restructure the whole program, as your variable gpa and the function that sets it would give you only the overall gpa of all the courses.
You should also think about how you want to store your variables before you rewrite, and this should allow you to write a shorter program with more functions that are reused.
I hope this was somewhat useful to you.
Further, please do not be offended but I would strongly urge you to cut and paste your code into a document editor like LibreOffice or MS Word and spell check it before submitting it to your instructor.