help with overloading

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <cstdio>
using namespace std;

void grade_converter(char);
char grade_converter(int,char);

int main(){
    char testOne, NewTestTwo;
    int testTwo;
    bool valid;
    
    do{
       valid=true;
       cout<<"Please enter the first test's letter grade: ";
       cin>>testOne;
       switch(testOne){
           case 'A':
           case 'B':
           case 'C':
           case 'D':
           case 'F':
                break;
           default:
               cout<<"\nInvalid grade!\n";
               valid=false;
       }
    }while(!valid);
    do{
       valid=true;
       cout<<"\nPlease enter the second test's score: ";
       cin>>testTwo;
       if (testTwo>100||testTwo<0){
          cout<<"\nInvalid Input!";
          valid=false;
       }
    }while(!valid);;         
    grade_converter(testOne);
    grade_converter(testTwo,NewTestTwo);
    cout<<"\nThe letter grade on your second test is "<<NewTestTwo;
    system("pause");
}

void grade_converter(char testOne){
     switch (testOne){
            case 'A':
                 cout<<"\nScore range for your first test is 90-100";
                 break;
            case 'B':
                 cout<<"\nScore range for your first test is 80-89";
                 break;
            case 'C':
                 cout<<"\nScore range for your first test is 70-79";
                 break;
            case 'D':
                 cout<<"\nScore range for your first test is 60-69";
                 break;
            case 'F':
                 cout<<"\nScore range for your first test is 0-59";
                 break;
            default:;
     }
}

char grade_converter(int testTwo,char NewTestTwo){
     if (testTwo>89){
         NewTestTwo='A';
     }if (testTwo>79&&testTwo<90){
         NewTestTwo='B';
     }if (testTwo>69&&testTwo<80){
         NewTestTwo='C';
     }if (testTwo>59&&testTwo<70){
         NewTestTwo='D';
     }if (testTwo<60){
         NewTestTwo='F';
     }
     return(NewTestTwo);
}
          


For some reason the letter grade ("NewTestTwo") wont display, am I not returning it correctly to the main function?
grade converter (the one that takes 2 parameters) returns a value but you're not doing anything with it.

I think you meant NewTestTwo = grade_converter(testTwo,NewTestTwo);

the other grade converter function (1 parameter) is used in the same way, but since you do the output inside of that function you still see the result
Last edited on
Ahh thank you very much bro!
Topic archived. No new replies allowed.