global variables

In this code, I have defined the five score variables before anything else, and yet, the variables always remain zero. What am I doing wrong that is preventing them from being accessed anywhere in the program?
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>

using namespace std;

int score1, score2, score3, score4, score5;
void getScore(int &);
void calcAverage();
int findLowest(int);


int main ()

{
     cout<<"Welcome. The intent of this program is to intake five test scores from the \n";
     cout<<"user, take out the lowest score, and average them together. \n";
     cout<<"When asked to input a score, please do not enter a number less than 0 or higher than 100.\n";
      
     for (int count=1; count<=5; count++)
         {
             int test;
             getScore(test);
              
              switch (count)
     {case 1: test=score1;
          break;
     case 2: test=score2;
          break;
     case 3: test=score3;
          break;
     case 4: test=score4;
          break;
     case 5: test=score5;}
              
            
              
              
              
              
              
              }
              
         calcAverage();
         system ("pause");
         return 0;
}

void getScore(int &sco)

{
     
     
    
     {cout<<"Please enter a test score:";
     cin>>sco ;
     while (sco >100|| sco<0)
        {cout<<"Your entry is invalid, please try again: ";
        cin>>sco;}
        
        
     
}
}
     void calcAverage()
{
  int lowscore;   
  double average;   
     
     
    lowscore=findLowest(lowscore);
  

       if (score1==lowscore)
             {
              average=(score2+score3+score4+score5)/4.0;
              cout<<"The average of the four highest test scores is " <<average <<".";
              
                      
              }
       else
              {
                     if (score2==lowscore)
                     {
                       average=(score1+score3+score4+score5)/4.0;
              cout<<"The average of the four highest test scores is " <<average <<".";
                         }
                     else
                     {
                                 if (score3==lowscore)
                                 {
                                   average=(score2+score1+score4+score5)/4.0;
              cout<<"The average of the four highest test scores is " <<average <<".";
                                 }
                                 else
                                 {   
                                             if (score4==lowscore)
                                             {
                                               average=(score2+score3+score1+score5)/4.0;
              cout<<"The average of the four highest test scores is " <<average <<".";
                                             }
                                             else
                                             {
                                                         average=(score2+score3+score4+score1)/4.0;
              cout<<"The average of the four highest test scores is " <<average <<".";
                                             }
                                }

                       }
              }

}

int findLowest(int lowest)

{
    
        for(int tick=0; tick<5;)
       {     
           while (tick==0)
                { lowest=score1;
                tick++; }
           while (tick==1)
                 { while (score2<lowest)
                         {lowest=score2; }
                  tick++;}       
           while (tick==2)
                 { while (score3<lowest)
                         {lowest=score3; }
                  tick++;}                
           while (tick==3)
                 { while (score4<lowest)
                         {lowest=score4; }
                  tick++;}                  
           while (tick==4)
                 { while (score5<lowest)
                         {lowest=score5; }
                  tick++;}
                  
                  return lowest;}
}  

     
         
1
2
3
4
5
6
7
8
9
10
11
 
     switch (count){
     case 1: test=score1;
          break;
     case 2: test=score2;
          break;
     case 3: test=score3;
          break;
     case 4: test=score4;
          break;
     case 5: test=score5;}

should be
1
2
3
4
5
6
7
8
9
10
11
 
     switch (count){
     case 1: score1=test;
          break;
     case 2: score2=test;
          break;
     case 3: score3=test;
          break;
     case 4: score4=test;
          break;
     case 5: score5=test;}


in your version you are assigning scores to test and scores never get a value
Last edited on
Topic archived. No new replies allowed.