inline function

OK I am having trouble with inline functions. Every website I go too either shows how to use void, or a variable, but never both.
The program is suppose to have two functions. 1 to calculate average of grades, and 2 display statistics of grade ranges.

In the code you see below, I first created the code to run, with only one function that calculates the average. Now I am trying to improve it by moving the statistical readout to a function, but I can't figure it out. please help

the original code
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
vector::push_back
#include <iostream>
#include <vector>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
using namespace std;

inline double average(double sum, int size )//Get average of grades
{
  return   ( sum/size);
}

int main ()
{
  std::vector<int> myvector;
  float a=0; //90 - 100
  float b=0; //80 - 89
  float c=0; //70 - 79
  float d=0; //60 - 69
  float e=0; //50 - 69
  float f=0; //40 - 59
  float g=0; //30 - 39
  float h=0; //20 - 29
  float i=0; //10 - 19
  float j=0; //0 - 9*/
  int count=0;
  float myint=0;
  int size=0;
  double sum=0;
  int temp =0;

//Get grade input


  while (temp !=-1){
  	 cout << "Please enter a grade between() 0 and 100):\n";
 	 cout << "Enter -1 when finished:\n";
 	 
    cin >> temp;
    if(temp > 100 || temp < -1)//verify if grade is legitimate grade
    
    {count = count + 1; //count number of illegitimate grades
	cout << "Please enter a grade between 0 and 100):\n";
	sum = sum - temp;// remove illgitimate grade from sum of all grades
    }
	myint = temp;
    myvector.push_back (myint) ;
    sum = sum + myint;// Calculate total of all legitimate grades

    //Get number of students in each grade category 
   		 if (myint>= 90 && myint< 101){
    			a = a +1;
    			}
    		else if (myint>= 80 && myint < 90){
    			b = b +1;
    			}
    		else if (myint>= 70 && myint < 80){
    			c = c +1;
    			}
    		else if (myint>= 60 && myint < 70){
    			d = d +1;
    			}
    		else if (myint>= 50 && myint < 60){
    			e = e +1;
    			}
    		else if (myint>= 40 && myint < 50){
    			f = f +1;
    			}
    		else if (myint>= 30 && myint < 40){
    			g = g +1;
    			}
    		else if (myint>= 20 && myint < 30){
    			h = h +1;
    			}
    		else if (myint>= 10 && myint < 20){
    			i = i +1;
    			}
    		else if (myint>= 0 && myint < 10 ){
    			j = j +1;
    			} 
				
				
				size = (myvector.size()-1); 
				size = size - count;
  }  
  
  //sum of grades
  sum = sum + 1;
  
   // std::cout << "myvector stores " << int(myvector.size()) << " numbers.\n";
    
  //count number of legitimate grades

  //size = size - count;
  
  system("cls");
  
 //Output statistics 
 
  cout <<"sum :"<< sum << endl;
 cout <<"Class statistics:" << endl;
 cout <<"The number of grades you entered was: " << size << endl;
 system("Color 1A");
 cout<< "Class Average: " << average(sum, size) << endl;
  cout<< "Grades: " << endl;

  	 cout <<"0 - 9.99:    " << j <<  endl;
	 cout <<"10 - 19.99:  " << i <<  endl;
	 cout <<"20 - 29.99:  " << h<<  endl;
	 cout <<"30 - 39.99:  " << g<<  endl;
	 cout <<"40 - 49.99:  " << f<<  endl;
	 cout <<"50 - 59.99:  " << e<<  endl;
	 cout <<"60 - 69.99:  " << d<<  endl;
	 cout <<"70 - 79.99:  " << c<<  endl;
	 cout <<"80 - 89.99:  " << b<<  endl;
	 cout <<"90 - 100:    " << a<<  endl;
  //grades();
 
  
 
// cout <<"size is" << size << endl;
//  cout <<"count is" << count << endl;
 
 system("PAUSE");
  return 0;
}


this code is my attempt to use the statistical 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  // vector::push_back
#include <iostream>
#include <vector>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
using namespace std;

inline double average(double sum, int size )//Get average of grades
{
  return   ( sum/size);
}

inline float Statistics( )//Get average of grades
{int a ; int b ; int c; int d ; 
int e; int f; int g; int h; int i; int j; int myint;

			 if (myint>= 90 && myint< 101){
    			a = a +1;
    			}
    		else if (myint>= 80 && myint < 90){
    			b = b +1;
    			}
    		else if (myint>= 70 && myint < 80){
    			c = c +1;
    			}
    		else if (myint>= 60 && myint < 70){
    			d = d +1;
    			}
    		else if (myint>= 50 && myint < 60){
    			e = e +1;
    			}
    		else if (myint>= 40 && myint < 50){
    			f = f +1;
    			}
    		else if (myint>= 30 && myint < 40){
    			g = g +1;
    			}
    		else if (myint>= 20 && myint < 30){
    			h = h +1;
    			}
    		else if (myint>= 10 && myint < 20){
    			i = i +1;
    			}
    		else if (myint>= 0 && myint < 10 ){
    			j = j +1;
    			} 
    			
     cout <<"0 - 9.99:    " << j <<  endl;
	 cout <<"10 - 19.99:  " << i <<  endl;
	 cout <<"20 - 29.99:  " << h<<  endl;
	 cout <<"30 - 39.99:  " << g<<  endl;
	 cout <<"40 - 49.99:  " << f<<  endl;
	 cout <<"50 - 59.99:  " << e<<  endl;
	 cout <<"60 - 69.99:  " << d<<  endl;
	 cout <<"70 - 79.99:  " << c<<  endl;
	 cout <<"80 - 89.99:  " << b<<  endl;
	 cout <<"90 - 100:    " << a<<  endl;
	
  return   ( a,b,c,d,e,f,g,h,i,j);
}

int main ()
{
  std::vector<int> myvector;
/*  float a=0; //90 - 100
  float b=0; //80 - 89
  float c=0; //70 - 79
  float d=0; //60 - 69
  float e=0; //50 - 69
  float f=0; //40 - 59
  float g=0; //30 - 39
  float h=0; //20 - 29
  float i=0; //10 - 19
  float j=0; //0 - 9*/
  int count=0;
  float myint=0;
  int size=0;
  double sum=0;
  int temp =0;

//Get grade input
// cout << "Please enter a grade between() 0 and 100):\n";
// cout << "Enter -1 when finished:\n";

  while (temp !=-1){
  	 cout << "Please enter a grade between() 0 and 100):\n";
 	 cout << "Enter -1 when finished:\n";
 	 
    std::cin >> temp;
    if(temp > 100 || temp < -1)//verify if grade is legitimate grade
    
    {//count = count + 1; //count number of illegitimate grades
	cout << "Please enter a grade between 0 and 100):\n";
	//sum = sum - myint;// remove illgitimate grade from sum of all grades
    }
	myint = temp;
    myvector.push_back (myint) ;
    sum = sum + myint;// Calculate total of all legitimate grades
   // Statistics();
    //Get number of students in each grade category 
   	/*	 if (myint>= 90 && myint< 101){
    			a = a +1;
    			}
    		else if (myint>= 80 && myint < 90){
    			b = b +1;
    			}
    		else if (myint>= 70 && myint < 80){
    			c = c +1;
    			}
    		else if (myint>= 60 && myint < 70){
    			d = d +1;
    			}
    		else if (myint>= 50 && myint < 60){
    			e = e +1;
    			}
    		else if (myint>= 40 && myint < 50){
    			f = f +1;
    			}
    		else if (myint>= 30 && myint < 40){
    			g = g +1;
    			}
    		else if (myint>= 20 && myint < 30){
    			h = h +1;
    			}
    		else if (myint>= 10 && myint < 20){
    			i = i +1;
    			}
    		else if (myint>= 0 && myint < 10 ){
    			j = j +1;
    			} */
				
				
				size = (myvector.size()-1); 
  }  
  
  //sum of grades
  sum = sum + 1;
  
   // std::cout << "myvector stores " << int(myvector.size()) << " numbers.\n";
    
  //count number of legitimate grades

  //size = size - count;
  
  system("cls");
  
 //Output statistics 
 
  cout <<"sum :"<< sum << endl;
 cout <<"Class statistics:" << endl;
 cout <<"The number of grades you entered was: " << size << endl;
 system("Color 1A");
 cout<< "Class Average: " << average(sum, size) << endl;
  cout<< "Grades: " << endl;
  Statistics();
  	/* cout <<"0 - 9.99:    " << Statistics(j) <<  endl;
	 cout <<"10 - 19.99:  " << i <<  endl;
	 cout <<"20 - 29.99:  " << h<<  endl;
	 cout <<"30 - 39.99:  " << g<<  endl;
	 cout <<"40 - 49.99:  " << f<<  endl;
	 cout <<"50 - 59.99:  " << e<<  endl;
	 cout <<"60 - 69.99:  " << d<<  endl;
	 cout <<"70 - 79.99:  " << c<<  endl;
	 cout <<"80 - 89.99:  " << b<<  endl;
	 cout <<"90 - 100:    " << a<<  endl;*/
  //grades(); 
// cout <<"size is" << size << endl;
//  cout <<"count is" << count << endl;
 
 system("PAUSE");
  return 0;
}
inline float Statistics( )
A function that takes no argument an returns one floating point number.

return ( a,b,c,d,e,f,g,h,i,j);
¿what do you think you are doing there?

If you wish to return more than one variable you must using output parameters via pointer, reference, or a combination.
ok..I will try to figure out how to use a reference.. any hints you can give me on that?
1
2
3
4
5
6
void someFunction( int &a, int &b , int &c , int &ect....)
{
    //you are now passing the actual object and not a copy
   //so when you modify here the one being passed is modified.
   a = 10; //a is now 10 outside the function
};


http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/ -all of chapter 7 might help
http://www.cplusplus.com/doc/tutorial/functions/
Ok so I read about reference and and pointers..and I can't figure out how to apply eithe rof them to my code.. I'm more confused now. Can somebody give me a meaningful example that uses a function with more than one variable to output from function like my code above..

Can someone help who is willing to teach and not brush me off by saying go read about pointers or references..etc..
thank you

The examples I read that I couldn't figure out how to apply are the following

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
#include <iostream>
#include <ctime>
 
using namespace std;
 
// function to generate and retrun random numbers.
int * getRandom( )
{
  static int  r[10];
 
  // set the seed
  srand( (unsigned)time( NULL ) );
  for (int i = 0; i < 10; ++i)
  {
    r[i] = rand();
    cout << r[i] << endl;
  }
 
  return r;
}
 
// main function to call above defined function.
int main ()
{
   // a pointer to an int.
   int *p;
 
   p = getRandom();
   for ( int i = 0; i < 10; i++ )
   {
       cout << "*(p + " << i << ") : ";
       cout << *(p + i) << endl;
   }
 
   return 0;
}


another example is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
 
using namespace std;
const int MAX = 3;
 
int main ()
{
   int  var[MAX] = {10, 100, 200};
   int *ptr[MAX];
 
   for (int i = 0; i < MAX; i++)
   {
      ptr[i] = &var[i]; // assign the address of integer.
   }
   for (int i = 0; i < MAX; i++)
   {
      cout << "Value of var[" << i << "] = ";
      cout << *ptr[i] << endl;
   }
   return 0;
}


on using reference

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

#include <iostream>
#include <ctime>
 
using namespace std;
 
double vals[] = {10.1, 12.6, 33.1, 24.1, 50.0};
 
double& setValues( int i )
{
  return vals[i];   // return a reference to the ith element
}
 
// main function to call above defined function.
int main ()
{
 
   cout << "Value before change" << endl;
   for ( int i = 0; i < 5; i++ )
   {
       cout << "vals[" << i << "] = ";
       cout << vals[i] << endl;
   }
 
   setValues(1) = 20.23; // change 2nd element
   setValues(3) = 70.8;  // change 4th element
 
   cout << "Value after change" << endl;
   for ( int i = 0; i < 5; i++ )
   {
       cout << "vals[" << i << "] = ";
       cout << vals[i] << endl;
   }
   return 0;
}
thanks Giblit.. I will try that....
giblit..
I check out the tutorial you posted.. I'm close but no cigar.

Its printing out a weired number instead of the value. probably the address.

so look at lines 14 - 20 for the function with a reference call to &a
and then line 153 for the print out of the value a..
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 // vector::push_back
#include <iostream>
#include <vector>
#include <cstdlib>
#include <stdio.h>
#include <iostream>
using namespace std;

inline double average(double sum, int size )//Get average of grades
{
  return   ( sum/size);
}

void  Statistics(int &a )//Get average of grades
{int myint;

			 if (myint>= 90 && myint< 101){
    			//int count(int a){	a = a +1; return a;}
    			a = a +1;
    			}
    		else if (myint>= 80 && myint < 90){
    		//	int count(int b){	b = b +1 return b;}
       			}
    		else if (myint>= 70 && myint < 80){
    		//	int count(int c){	c = c +1; return c;}
       			}
    		else if (myint>= 60 && myint < 70){
    			//int count(int d){	d = d +1; return d;}
    			}
    		else if (myint>= 50 && myint < 60){
    		//	int count(int e){	e = e +1; return e;}
    			}
    		else if (myint>= 40 && myint < 50){
    		//	int count(int f){	f = f +1; return f;}
    			}
    		else if (myint>= 30 && myint < 40){
    		//	int count(int g){	g = g +1; return g;}
    			}
    		else if (myint>= 20 && myint < 30){
    		//	int count(int h){	h = h +1; return h;}
     			}
    		else if (myint>= 10 && myint < 20){
    		//	int count(int i){	i = i +1; return i;}
    			}
    		else if (myint>= 0 && myint < 10 ){
    		//	int count(int j){	j = j +1; return j;}
    			} 
    			
   /*  cout <<"0 - 9.99:    " << j <<  endl;
	 cout <<"10 - 19.99:  " << i <<  endl;
	 cout <<"20 - 29.99:  " << h<<  endl;
	 cout <<"30 - 39.99:  " << g<<  endl;
	 cout <<"40 - 49.99:  " << f<<  endl;
	 cout <<"50 - 59.99:  " << e<<  endl;
	 cout <<"60 - 69.99:  " << d<<  endl;
	 cout <<"70 - 79.99:  " << c<<  endl;
	 cout <<"80 - 89.99:  " << b<<  endl;
	 cout <<"90 - 100:    " << a<<  endl;*/
	
 
}

int main ()
{
  std::vector<int> myvector;
  int a; //90 - 100
  float b=0; //80 - 89
  float c=0; //70 - 79
  float d=0; //60 - 69
  float e=0; //50 - 69
  float f=0; //40 - 59
  float g=0; //30 - 39
  float h=0; //20 - 29
  float i=0; //10 - 19
  float j=0; //0 - 9
  int count=0;
  float myint=0;
  int size=0;
  double sum=0;
  int temp =0;
  int *ia;
  //ia = &a;
  
//Get grade input
// cout << "Please enter a grade between() 0 and 100):\n";
// cout << "Enter -1 when finished:\n";

  while (temp !=-1){
  	 cout << "Please enter a grade between() 0 and 100):\n";
 	 cout << "Enter -1 when finished:\n";
 	 
    std::cin >> temp;
    if(temp > 100 || temp < -1)//verify if grade is legitimate grade
    
    {//count = count + 1; //count number of illegitimate grades
	cout << "Please enter a grade between 0 and 100):\n";
	//sum = sum - myint;// remove illgitimate grade from sum of all grades
    }Statistics(a);
	myint = temp;
    myvector.push_back (myint) ;
    sum = sum + myint;// Calculate total of all legitimate grades
   // Statistics();
    //Get number of students in each grade category 
   	/*	 if (myint>= 90 && myint< 101){
    			a = a +1;
    			}
    		else if (myint>= 80 && myint < 90){
    			b = b +1;
    			}
    		else if (myint>= 70 && myint < 80){
    			c = c +1;
    			}
    		else if (myint>= 60 && myint < 70){
    			d = d +1;
    			}
    		else if (myint>= 50 && myint < 60){
    			e = e +1;
    			}
    		else if (myint>= 40 && myint < 50){
    			f = f +1;
    			}
    		else if (myint>= 30 && myint < 40){
    			g = g +1;
    			}
    		else if (myint>= 20 && myint < 30){
    			h = h +1;
    			}
    		else if (myint>= 10 && myint < 20){
    			i = i +1;
    			}
    		else if (myint>= 0 && myint < 10 ){
    			j = j +1;
    			} */
				
				
				size = (myvector.size()-1); 
  }  
  
  //sum of grades
  sum = sum + 1;
    
  //count number of legitimate grades

system("cls");
  
 //Output statistics 
  system("Color 1A");
  cout <<"sum :"<< sum << endl;
 cout <<"Class statistics:" << endl;
 cout <<"The number of grades you entered was: " << size << endl;
  cout<< "Class Average: " << average(sum, size) << endl;
  cout<< "Grades: " << endl;
 	 cout <<"90 - 100:    " << a <<  endl;
 /* 	 cout <<"0 - 9.99:    " << j <<  endl;
	 cout <<"10 - 19.99:  " << i <<  endl;
	 cout <<"20 - 29.99:  " << h<<  endl;
	 cout <<"30 - 39.99:  " << g<<  endl;
	 cout <<"40 - 49.99:  " << f<<  endl;
	 cout <<"50 - 59.99:  " << e<<  endl;
	 cout <<"60 - 69.99:  " << d<<  endl;
	 cout <<"70 - 79.99:  " << c<<  endl;
	 cout <<"80 - 89.99:  " << b<<  endl;
	 cout <<"90 - 100:    " << *ia<<  endl;*/

 
 system("PAUSE");
  return 0;


The output from line 153...the value should be "2"


90 - 100:   2686716

well myint is undefined. int myint;
Topic archived. No new replies allowed.