functions

I have been working on this all day and I just can't get it. I go back and look in my C++ companion guide as I read the chapter and this is like a foreign language to me. I have read the tutorials and everything I try and does not work. I am at the point of pulling my hair out.

Can someone please point me in the right direction? I am trying to put this in Dev but for the life of me I cannot get it correct.

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
80
81
82
83
84
85
86
87
88
89
90
  #include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    // main module
int main()
    // Local variables
int average

    // Get scores
    //Call getScores(average)

    // Show average grade
    //Call showAverage(average)


End Module
    // The getScores module gets object mass

    Module getScores(Int Ref average)
    In entry, inputAmount, s1, s2, s3, s4, s5, average
    count<< "Enter 5 test scores:  "
For entry = 1 to 5
    count<< "Enter number ", entry, " score: "
    cin>> inputAmount
    Select entry
    Case 1:
    Set s1 = inputAmount
    Case 2:
    Set s2 = inputAmount
    Case 3:
    Set s3 = inputAmount
    Case 4:
    Set s4 = inputAmount
    Case 5:
    Set s5 = inputAmount
End function 
    // show letter grade
    count<< "The grade is ", determineGrade(inputAmount)
End For

    // calculate average grade
    Set average = calcAverage(s1, s2, s3, s4, s5)
End Module

    // The showAverage module shows kinetic energy
Module showAverage(Int average)

       count<< "Average score: ", average
       count<< "Letter grade: ",determineGrade(average)

End Module

// The calcAverage function returns average of 5 grades
Function Integer calcAverage(Integer s1, s2, s3, s4, s5)
Declare Integer answer

Set answer = (s1 + s2 + s3 + s4 + s5) / 5
Return answer

End Function

// The determineGrade function returns letter grade
Function String determineGrade(Int score)

If score >= 90 then
Return "A"
Else
If Score >= 80 Then
Return "B"
Else
If score >= 70 Then
Return "C"
Else
If score >= 60 Then
Return "D"
Else
Return "F"
End If
End If
End If
End If

End Function
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
You appear to be mixing C++ with ?Visual Basic?

There are too many mistakes here for me to point out. I can only recommend you go through a quick tutorial on C++ language basics.
Thanks for taking the time to look at this. I am still working on it and hopefully I will figure it out.

This is the exercise i'm working on.

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Design the following functions in the program:
● calcAverage—This function should accept five test scores as arguments and return the average of the scores.
● determineGrade—This function should accept a test score as an argument and return a letter grade for the score (as a String), based on the following grading scale:
Score Letter Grade
90–100 A
80–89 B
70–79 C
60–69 D
Below 60 F
Last edited on
The logic in your post is close to what you need... you're just not writing the code in the correct language.

Look up the tutorials on this site about how to create functions and 'if' statements. You'll see it's totally different from what you have posted.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void somefunction()
{
    // code inside that function
}

int main()
{
    // call the function we just created
    somefunction();

    // do an if statement:
    if( 3+2 == 5 )
    {
        // do something if the above condition is true
    }
    else
    {
        // do something if the above condition is false
    }
}
Thanks Disch i'm trying
Topic archived. No new replies allowed.