C++ question

This is a discussion on C++ question within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a bit of as problem. This file should calculate cut-off grades and then re-print out the file ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    C++ question

    Hi,

    I have a bit of as problem. This file should calculate cut-off grades and then re-print out the file containing student grades and assign grades A, B, C, and D to the three exam scores as well as the total scores. I have attached the code so that it's easier to read. As you can see, I have stored all my values in parallel arrays. The cut-off grades are printing out nicely. My problem is that , I have created two char variables grade1 and grade2(just to test) to convert the marks to grades. I am hoping to replicate the if and else(if it works) for the grade for the third exam, as well as the total(final) grade. My logic seems to make sense, but after repeatedly trying different scenarios, the program is assigning wrong grades(A, B,C and D) to the student marks. Could anyone point out what's wrong with my if and else statements? Thanks a lot....
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    C ++

    It seems the file did not attach properly. I am pasting the relevant part of the code. Please bear with me because I don't know how to format it for this forum as suggested.

    for(i=0; i<SIZE; i++)
    {

    inFile>>name[i]>>exam1Array[i]>>exam2Array[i]>>exam3Array[i];

    }


    cutoffArrayForAs[0]= GetHighValue(exam1Array)*0.9;
    cutoffArrayForAs[1]= GetHighValue(exam2Array)*0.9;
    cutoffArrayForAs[2]= GetHighValue(exam3Array)*0.9;

    cutoffArrayForBs[0]= GetHighValue(exam1Array)*0.8;
    cutoffArrayForBs[1]= GetHighValue(exam2Array)*0.8;
    cutoffArrayForBs[2]= GetHighValue(exam3Array)*0.8;

    cutoffArrayForCs[0]= GetHighValue(exam1Array)*0.7;
    cutoffArrayForCs[1]= GetHighValue(exam2Array)*0.7;
    cutoffArrayForCs[2]= GetHighValue(exam3Array)*0.7;

    cutoffArrayForDs[0]= GetHighValue(exam1Array)*0.6;
    cutoffArrayForDs[1]= GetHighValue(exam2Array)*0.6;
    cutoffArrayForDs[2]= GetHighValue(exam3Array)*0.6;

    cutoffArrayForTotals[0]=GetHighValue(exam1Array)*0.9+GetHighValue(exam2Ar ray)*0.9+GetHighValue(exam3Array)*0.9;
    cutoffArrayForTotals[1]=GetHighValue(exam1Array)*0.8+GetHighValue(exam2Ar ray)*0.8+GetHighValue(exam3Array)*0.8;
    cutoffArrayForTotals[2]=GetHighValue(exam1Array)*0.7+GetHighValue(exam2Ar ray)*0.7+GetHighValue(exam3Array)*0.7;
    cutoffArrayForTotals[3]=GetHighValue(exam1Array)*0.6+GetHighValue(exam2Ar ray)*0.6+GetHighValue(exam3Array)*0.6;




    cout<<setw(30)<<" CST 150 Grade Summary"<<endl;
    cout<<endl;
    cout<<setw(18)<<" Exam1:"<<setw(18)<<" Exam2:"<<setw(18)<<" Exam3:"<<setw(20)<<" Total:"<<endl;

    cout<<"A cut-off="<<setw(3)<<cutoffArrayForAs[0]<<setw(18)<<cutoffArrayForAs[1]<<setw(18)<<cutoffArrayForAs[2]<<setw(20)<<cutoffArrayForTotals[0]<<endl;
    cout<<"B cut-off="<<setw(3)<<cutoffArrayForBs[0]<<setw(18)<<cutoffArrayForBs[1]<<setw(18)<<cutoffArrayForBs[2]<<setw(20)<<cutoffArrayForTotals[1]<<endl;
    cout<<"C cut-off="<<setw(3)<<cutoffArrayForCs[0]<<setw(18)<<cutoffArrayForCs[1]<<setw(18)<<cutoffArrayForCs[2]<<setw(20)<<cutoffArrayForTotals[2]<<endl;
    cout<<"D cut-off="<<setw(3)<<cutoffArrayForDs[0]<<setw(18)<<cutoffArrayForDs[1]<<setw(18)<<cutoffArrayForDs[2]<<setw(20)<<cutoffArrayForTotals[3]<<endl;

    cout<<"Student Results and Grades:"<<endl;


    for(i=0; i<SIZE; i++)
    {

    cout<<name[i]<<setw(6)<<exam1Array[i]<<'='<<grade1<<setw(16)<<exam2Array[i]<<'='<<grade2<<setw(18)<<exam3Array[i]<<'='<<setw(18)<<exam1Array[i]+exam2Array[i]+exam3Array[i]<<'='<<endl;

    {
    if(exam1Array[i]>=cutoffArrayForAs[0])
    grade1='A';
    else if(exam1Array[i]>=cutoffArrayForBs[0])
    grade1='B';
    else if(exam1Array[i]>=cutoffArrayForCs[0])
    grade1='C';
    else
    grade1='D';

    }

    {
    if(exam2Array[i]>=cutoffArrayForAs[1])
    grade2='A';
    else if(exam2Array[i]>=cutoffArrayForBs[1])
    grade2='B';
    else if(exam2Array[i]>=cutoffArrayForCs[1])
    grade2='C';
    else
    grade2='D';
    }
    }






    return 0;
    }




    int GetHighValue(/*in*/ int array[])
    {
    int highScore=0;
    int i=0;
    for(i=0; i<SIZE; i++)
    {
    if(array[i]>highScore)
    highScore=array[i];


    }

    return highScore;
    }
    Last edited by brainstormin; 08-03-2006 at 11:36 AM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    Gee, ya think ya can use code tags yet?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    9

    code tag

    Please show me how to use the code tags..

  5. #5
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    Could you copy and paste your Grades.dat file?

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    9
    This is the most relevant part:





    for(i=0; i<SIZE; i++)
    {

    cout<<name[i]<<setw(6)<<exam1Array[i]<<'='<<grade1<<setw(16)<<exam2Array[i]<<'='<<grade2<<setw(18)<<exam3Array[i]<<'='<<setw(18)<<exam1Array[i]+exam2Array[i]+exam3Array[i]<<'='<<endl;

    {
    if(exam1Array[i]>=cutoffArrayForAs[0])
    grade1='A';
    else if(exam1Array[i]>=cutoffArrayForBs[0])
    grade1='B';
    else if(exam1Array[i]>=cutoffArrayForCs[0])
    grade1='C';
    else
    grade1='D';

    }

    {
    if(exam2Array[i]>=cutoffArrayForAs[1])
    grade2='A';
    else if(exam2Array[i]>=cutoffArrayForBs[1])
    grade2='B';
    else if(exam2Array[i]>=cutoffArrayForCs[1])
    grade2='C';
    else
    grade2='D';
    }
    }

  7. #7
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    Quote Originally Posted by brainstormin
    Please show me how to use the code tags..

    Type in [code] then some junk you want to be in the code box (your code) and then type [/ code] (without that space).

    Code:
    this is code
    or just edit this post and paste your code where mine reads "this is code"

  8. #8
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    Closed until you learn to use the board properly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21