| | |
slowly but surely
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
This is still the readStuData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany) assignment. I've hit a small snag. This piece of the code works....kind of. When the program is run it prints out the table and stuff, however, when printing the grade it doesn't do it correctly. If I take away the for-loop code for printGrade and just leave the if statements, then hardcode 'int i = #', where # = a number from 0 - 21, it will print that one id and score repeatedly as well as the correct "grade" with it. But if left as is, it doesn't print "grade" correctly.
Not sure where the issue lies with this one.
Not sure where the issue lies with this one.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; void printTable(int score[], int id[], int count) { void printGrade(int oneScore, float average); const int MAX_SIZE = 21; int oneScore = 0; float average = 0; string grade; id[MAX_SIZE]; score[MAX_SIZE]; cout << left << setw(9) << "ID#s" << setw(9) << "Scores" << setw(9) << "Grades" << endl << endl; //for(count = 0; count < MAX_SIZE; count++) //{ printGrade(oneScore,average); //} } void printGrade(int oneScore, float average) { const int MAX_SIZE = 21; int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121}; int scores[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0}; oneScore = 0; average = 0; string grade; for(int i = 0; i < MAX_SIZE; i++) { oneScore = oneScore + scores[i]; average = oneScore / MAX_SIZE; if(scores[i] > average + 10) { grade = "outstanding"; } else if(scores[i] < average - 10) { grade = "unsatisfactory"; } else { grade = "satisfactory"; } cout << left << setw(9) << id[i] << setw(9) << scores[i] << setw(9) << grade << endl; } } int main() { const int MAX_SIZE = 21; int id[MAX_SIZE] = {101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121}; int score[MAX_SIZE] = {100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5,0}; int count = 0; int oneScore = 0; float average = 0; printTable(score, id, count); return 0; }
Last edited by Ancient Dragon; Jul 3rd, 2009 at 1:19 pm. Reason: add line numbers
With the dragons I fly and with wolves I run through the lands of myth and worlds unknown.
Its not calculating the average score correctly. It should be <sum of all scores> / MAX_SIZE. To do that you need another loop before the one you already have
Now delete lines 37 and 38 in the code snippet you posted.
C++ Syntax (Toggle Plain Text)
int sum = 0; for(int i = 0; i < MAX_SIZE; i++) sum += scores[i]; average = sum / MAX_SIZE;
Now delete lines 37 and 38 in the code snippet you posted.
Last edited by Ancient Dragon; Jul 3rd, 2009 at 1:20 pm.
![]() |
Similar Threads
- counting lesson(for the slow among us) (Posting Games)
- Hello everyone! (Community Introductions)
- Introduction (Community Introductions)
- New here! (Community Introductions)
- Centering a form in VB.NET (VB.NET)
- How much of a power supply is enough? (Motherboards, CPUs and RAM)
- found a trojan (Viruses, Spyware and other Nasties)
- May have Virus/Spyware/Aliens? or IE Hijacked (Viruses, Spyware and other Nasties)
- Still working !! (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: C++ arrays
- Next Thread: C++ -- Creating file but unable to delete it
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






