View Full Version : C++ help
Skhorpion
January 2nd, 2006, 02:01 PM
ok i was bored and decided to make a really long "Ultimate grade report" for teachers (even though teachers wont use it) and im stuck
i want them to be able to type Y or N to decide which things they want to see but it either doest let me type or shows it anyway, heres the part where it asks you
cout << "Phase 3\n"
<< "Phase 3 consists of relaying you teh information\n\n\n\n" << endl;
cout << "Would you like to see the class average? Y/N\n" << endl;
if (phase3 = cin.get()) {
switch (phase3) {
case 'Y':
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
break;
}
}
cout << fixed << setprecision (2) << phase1 << "\n\n" << endl;
cout << "Would you like to see the letter grades? Y/N" << endl;
phase3 = 0;
while (phase3 == 0) {
cin >> phase3;
switch (phase3) {
case 'Y':
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
continue;
}
}
cout << "\nA: " << aGrade
<< "\nB: " << bGrade
<< "\nC: " << cGrade
<< "\nD: " << dGrade
<< "\nF: " << fGrade
<< endl;
and kiros, i know you can probably compress that into like two lines but dont, i want to try to get it myself using what i know, i just cant for the life of me get this part
Kiros
January 2nd, 2006, 02:18 PM
cout << "Phase 3\n"
<< "Phase 3 consists of relaying you teh information\n\n\n\n" << endl;
cout << "Would you like to see the class average? Y/N\n" << endl;
//Did you forget the cin >> phase3; Or did you want to do the following in stead?
if (phase3 = cin.get()) { //Did you mean phase3 == cin.get() maybe?
//An IF statement really isn't something to set values with :?
switch (phase3) {
case 'Y': //Try to use "" for quotes, as it binds tighter than ''
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
break;
}
}
cout << fixed << setprecision (2) << phase1 << "\n\n" << endl;
cout << "Would you like to see the letter grades? Y/N" << endl;
phase3 = 0;
while (phase3 == 0) { //You should really use do..while instead of while and a continue :?
cin >> phase3;
switch (phase3) {
case 'Y':
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
continue;
}
}
cout << "\nA: " << aGrade
<< "\nB: " << bGrade
<< "\nC: " << cGrade
<< "\nD: " << dGrade
<< "\nF: " << fGrade
<< endl;
Ok, I've marked it up for you to check - read all the comments in it. And I am assuming you made an enumeration for your aGrade - fGrade, right?
Skhorpion
January 2nd, 2006, 02:40 PM
still didnt work.... here the entire thing as something i put earlier might be messing it up
#include <iostream>
using namespace std;
#include <iomanip>
#include <cstdlib>
int main()
{
int total = 0;
int gradeCounter = 0;
int grade;
int grader = 0;
int aGrade = 0;
int bGrade = 0;
int cGrade = 0;
int dGrade = 0;
int fGrade = 0;
int phase3;
double phase1;
cout << "Ultimate Grade Report\n"
<< "Enter grade to begin phase 1\n"
<< "Phase 1 consists of getting the class average\n"
<< "CTRL + Z to end\n";
cin >> grade;
while (grade != -1) {
total = total + grade;
gradeCounter++;
cout << "Enter grade\n";
cin >> grade;
}
if (gradeCounter != 0) {
phase1 = static_cast< double > (total) / gradeCounter;
}
else {
cout << "No Grades" << endl;
}
system ("cls");
cout << "Phase 2\n"
<< "Phase 2 consists of finding what grade letter the students got\n" << endl;
cout << "Enter student letter grade\n";
while ( (grader = cin.get() ) != EOF) {
switch (grader){
case 'A':
case 'a':
aGrade++;
break;
case 'B':
case 'b':
bGrade++;
break;
case 'C':
case 'c':
cGrade++;
break;
case 'D':
case 'd':
dGrade++;
break;
case 'F':
case 'f':
fGrade++;
break;
case '\n':
case '\t':
case ' ':
break;
default:
cout << "Incorrect grade, Please re-enter.";
break;
}
}
system ("cls");
cout << "Phase 3\n"
<< "Phase 3 consists of relaying you teh information\n\n\n\n" << endl;
cout << "Would you like to see the class average? Y/N\n" << endl;
//Did you forget the cin >> phase3; Or did you want to do the following in stead?
if (phase3 = cin.get()) { //Did you mean phase3 == cin.get() maybe?
//An IF statement really isn't something to set values with :?
switch (phase3) {
case 'Y': //Try to use "" for quotes, as it binds tighter than ''
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
break;
}
}
cout << fixed << setprecision (2) << phase1 << "\n\n" << endl;
cout << "Would you like to see the letter grades? Y/N" << endl;
phase3 = 0;
while (phase3 == 0) { //You should really use do..while instead of while and a continue :?
cin >> phase3;
switch (phase3) {
case 'Y':
case 'y':
phase3++;
break;
case 'N':
case 'n':
break;
if (phase3 == 0)
continue;
}
}
cout << "\nA: " << aGrade
<< "\nB: " << bGrade
<< "\nC: " << cGrade
<< "\nD: " << dGrade
<< "\nF: " << fGrade
<< endl;
cin.get();
return 0;
}
Kiros
January 2nd, 2006, 02:48 PM
Thanks for the code, I'll debug it...
Edit:
Ok... I'm not quite sure how to put this, but I have absolutely no idea where your logic is coming from :| For instance, you don't even need this: cout << fixed << setprecision (2). I don't know why you're using it. And further more, why this: while (grade != -1). That makes no sense :?
Maybe you should explain to me exactly what the program is for, what it should do, and how it should do it. Then I'll reconstruct this program for you...
Kiros
January 2nd, 2006, 06:46 PM
Bump.
Skhorpion
January 3rd, 2006, 03:20 PM
cout << fixed << setprecision (2) is to have it only display two decimal places and grade != -1 is using sentinel controlled repition, when user enter -1 as the grade it terminates
the program is an Ultimate Grade Report (still under construction apparebntly) that a teacher can enter the results of a test and have it display what the class average is and how many students got an A and a B etc
Kiros
January 3rd, 2006, 08:57 PM
Ughhh... I'm sorry, but that really does not make any sense :? It's not using sentinel controlled repetition! Not by the standard anyway :? And yes, you've said that description before, but that's extremely vague... :?
vBulletin® v3.8.9, Copyright ©2000-2021, vBulletin Solutions, Inc.