Problem with functions. specifically calling a function from within a function.

I am having trouble with a program that uses a function to get 5 numbers, then a function to find the lowest number and another function to average the four lowest. I am so fatigued that I am having trouble with the basics. I've used functions before but I really need some hints so I can refresh. I am taking a class next semester and I am just getting ready. Any hints will be helpful. p.s. I know i am a dummy so don't mind being obvious and don't worry I am not majoring in programming :)

This is what I am toiling with...



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

#include <cstdlib>
#include <iostream>

using namespace std;
void getScore(int,int,int,int,int);
void findLowest(int,int,int,int,int);
void calcAverage();


int main()
{
    int score1,score2,score3,score4,score5;
    
int calcAverage(int);
    
    // getSCore function to get user input
    
    int getScore(int num1,int num2,int num3,int num4,int num5);
   
    {int num1,num2,num3,num4,num5;
     cout<<"Enter a test score"<<endl;
     cin>>num1>>num2>>num3>>num4>>num5;
     
      return num1,num2,num3,num4,num5;
      }
      
      
 void calcAverage(int average)
  {
        int low;
low=findLowest(lowest);
low/4=average;
return average;}
     
      //findLowest function
      
     findLowest(num1,num2,num3,num4,num5)
    
     {  int num1,num2,num3,num4,num5;
      
 int lowest = num1;


if (num2<lowest)
{lowest=num2;
}
if(num3<lowest)
{lowest=num3;
}
if (num4<lowest)
{lowest=num4;
}
if (num5<lowest)
{lowest=num5;
}


return lowest;
}


   // just things i was toying with when i first started. 
   // may use. mite not need. for (int count=0;count<=5;count++)   // call getScore 5 times with for loop
  // getScore(score1,score2,score3,score4,score5);
       
    
    
    
    
    system("PAUSE");
    return 0;
}

The function call for CalcAverage doesn't match the prototype, nor does the function definition itself.

Same for the function call to findLowest.

You can't define functions inside of main; they're defined separately and called from main.

system("PAUSE"); is a bad idea.
alright thanks. that explains why i was having trouble compiling it. i"ll work on that. thanks ciphermagi - your living up to your name
ok. i've moved my functions outside of main. now i'm getting compiler error messages....

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

#include <cstdlib>
#include <iostream>

using namespace std;
int getScore(int,int,int,int,int);
int findLowest(int,int,int,int,int,int);
int calcAverage();


int main()
{
    int score1,score2,score3,score4,score5;
    
 calcAverage();
    
    
    
    
    
    
    system("PAUSE");
    return 0;
}
// getSCore function to get user input
    
    int getScore(int numbr1,int numbr2,int numbr3,int numbr4,int numbr5)
   {
    
     
     cout<<"Enter a test score"<<endl;
     cin>>numbr1>>numbr2>>numbr3>>numbr4>>numbr5;
     
      return numbr1,numbr2,numbr3,numbr4,numbr5;
      }
      
      // average to average four lowest scores
 int calcAverage(int average)
  {
      int lowest;
        int low;
low = findLowest(lowest);
low/4=average;
return average;}
     
      //findLowest function
      
   int findLowest(num1,num2,num3,num4,num5)
    
     {  int num1,num2,num3,num4,num5;
      
 int lowest = num1;


if (num2<lowest)
{lowest=num2;
}
if(num3<lowest)
{lowest=num3;
}
if (num4<lowest)
{lowest=num4;
}
if (num5<lowest)
{lowest=num5;
}


return lowest;
}


    
  
    
ok. so here's an update of my work.. i can't get my program to display my calcAverage function...

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
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;
void calcAverage (int,int,int,int,int);
void getScore(int &);
int findLowest(int,int,int,int,int);
      


int main()
{
    
      int score1,score2,score3,score4,score5;
    
 getScore(score1);
  getScore(score2);
   getScore(score3);
    getScore(score4);
     getScore(score5);
     
 calcAverage(score1,score2,score3,score4,score5);
 
    
          
    
    
    
    system("PAUSE");
    return 0;
}

// getSCore function to get user input
    
    void getScore(int &score)
  
    {
   int count=0;
   count++;
   
   cout<<"Enter a test score"<<endl;
   cin>>score;
     
  
      }
      
      
      //findLowest function
      
   int findLowest(int num1,int num2,int num3,int num4,int num5)
    
     {  
      
 int lowest = num1;


if (num2<lowest)
{lowest=num2;
}
if(num3<lowest)
{lowest=num3;
}
if (num4<lowest)
{lowest=num4;
}
if (num5<lowest)
{lowest=num5;
}


return lowest;
        }

      // function to average four lowest scores
 void calcAverage(int scor1,int scor2,int scor3,int scor4,int scor5)
  {
      
        
int lowest = 0;
double average;
	 
lowest = findLowest(scor1,scor2,scor3,scor4,scor5); 

 average =((scor1 + scor2 + scor3 + scor4 + scor5) - lowest) / 4 ; 

cout << "Your average is: " << average << endl;
  }    
    
    
  
    
Some of the issues are what ciphermagi already mentioned;

line 7: one too many arguments in the function findLowest()
line 38: you don't need to pass average into the definition for calcAverage()

About getScore: I don't think you can return more than one thing out of a function.

About calcAverage: You don't need to pass average into this function, average is just what you want to return. In the function, you will want to declare an integer average, so that the function knows what average is. Instead of low/4=average; it should be int average = low / 4;

Pass the array into findLowest(), and you'll have to re-engineer that function to return the four lowest scores; at the moment, it returns just one lowest score. As it is, you pass lowest when it's still undefined so it uses a nonsense value.
Last edited on
Thanks Lynnabelle:)
Topic archived. No new replies allowed.