Program Errors

Hello I have been working on this program I am having trouble compiling it and fixing my errors any suggestions on what to fix would be very helpful Thank You.


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
//compiler directives
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

//constant declarations

//function prototype

void GetData(int TestScoresf[], int &NumTestsf);
float ComputeAverage(int TestScoresf[]);
void PrintResults(int TestScoresf[],float Avgf);

//main body
int main ()
{

//local identifiers
float Average;
int TestScores, Numtests;
	
//function call

	GetData(TestScoresf, NumTestsf);
	Average = ComputeAverage(TestScores);
	PrintResults(TestScores,Average);
	
	cout<<"How many test scores do you have to enter?/n";
	cin<< NumTests;
	count=0;
	while (count++<NumTests);
	{

	return NumTests;
}
}

//function definitions

void GetData(int TestScoresf[], int &NumTestsf)
{
    
	{
		cout<<"Please enter Test Score #:"<<j+1<<"\t";
		cin>>TestScoresf[j];
		int j=0
		while ((TestScoresf[j]>=0)&(j<NumTests))
		{
              J++;
              cout<<"Please enter test score or -1 to exit<<j+1<<:l\t";
              cin>>TestScoresf[j];
              }
	}
	return;
}//end function

float ComputeAverage(int TestScoresf[])
{
	int sum=0;
	float avg;

	for(int j=0;j<NumTests;j++)
		sum+= TestScoresf[j];
	avg = float(sum/NumTests);

	return avg;

}//end function

void PrintResults(int TestScoresf[],float Avgf)
{
	cout<<"\n\n\n";
	cout<<setw(45)<<"GradeReport";
	cout<<"\n\n";
	cout<<setw(20)<<"Test#"<<setw(25)<<"Test Score";
	cout<<endl;
	
	for(int j=0; j<NumTests; j++)
	{	
	cout<<setw(23)<<j+1<<setw(30)<<TestScoresf[j]<<endl;
	cout<<"\n The Class Average is:\t";
	cout<<fixed<<showpoint<<setprecision(2)<<Avgf<<endl;

	return;
}
}
	//end of program 


:\TestScores2.cpp: In function `int main()':
I:\TestScores2.cpp:33: error: `TestScoresf' undeclared (first use this function)
I:\TestScores2.cpp:33: error: (Each undeclared identifier is reported only once for each function it appears in.)
I:\TestScores2.cpp:33: error: `NumTestsf' undeclared (first use this function)
I:\TestScores2.cpp:34: error: invalid conversion from `int' to `int*'
I:\TestScores2.cpp:34: error: initializing argument 1 of `float ComputeAverage(int*)'
I:\TestScores2.cpp:35: error: invalid conversion from `int' to `int*'
I:\TestScores2.cpp:35: error: initializing argument 1 of `void PrintResults(int*, float)'

I:\TestScores2.cpp:38: error: `NumTests' undeclared (first use this function)
I:\TestScores2.cpp:39: error: overloaded function with no contextual type information
I:\TestScores2.cpp:40: error: no post-increment operator for type

I:\TestScores2.cpp: In function `void GetData(int*, int&)':
I:\TestScores2.cpp:53: error: `j' undeclared (first use this function)
I:\TestScores2.cpp:56: error: expected `,' or `;' before "while"
I:\TestScores2.cpp: In function `float ComputeAverage(int*)':
I:\TestScores2.cpp:71: error: `NumTests' undeclared (first use this function)

I:\TestScores2.cpp: In function `void PrintResults(int*, float)':
I:\TestScores2.cpp:87: error: `NumTests' undeclared (first use this function)

I:\TestScores2.cpp:98:1: unterminated comment

Execution terminated
I think the error messages are self explaining, you have problems with declarations and function arguments
Yes they do explain the prob but I am not sure how to fix it I change something then I get more errors so for instance the NumTests being undeclard how would I fix it to declare it should I put an f behind it that doesnt work or declare it in the identifiers I thought since it was a function parameter it didnt have to be listed as an identifier oh I don't know I'm just at a lost at this point.
I have made some changes and got rid of some errors yet I still have a few I can't figure out.
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
//compiler directives
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

//constant declarations

//function prototype

void GetData(int TestScoresf[], int& NumTestsf);
float ComputeAverage(int TestScoresf[]);
void PrintResults(int TestScoresf[],float Avgf);

//main body
int main ()
{

//local identifiers
float Average;
int TestScoresf, Numtestsf;
	
//function call
    int NumTestsf;

	void GetData(int TestScoresf, int NumTestsf);
    Average =ComputeAverage(TestScoresf);
	PrintResults(TestScoresf,Average);
	
	cout<<"How many test scores do you have to enter?/n";
	cin<< NumTestsf;
	count=0;
	while (count++<NumTestsf);
	{

	return NumTestsf;
}
}

//function definitions

void GetData(int TestScoresf[], int& NumTestsf)
{
    int j;
	{
		cout<<"Please enter Test Score #:"<<j+1<<"\t";
		cin>>TestScoresf[j];
		int j=0;
		while ((TestScoresf[j]>=0)&(j<NumTests))
		{
              J++;
              cout<<"Please enter test score or -1 to exit<<j+1<<:l\t";
              cin>>TestScoresf[j];
              }
	}
	return;
}//end function

float ComputeAverage(int TestScoresf[])
{
	int sum=0;
	float avg;
    int NumTests;
	for(int j=0;j<NumTests;j++)
		sum+= TestScoresf[j];
	avg = float(sum/NumTests);

	return avg;

}//end function

void PrintResults(int TestScoresf[],float Avgf)
{
     int NumTests;
     
	cout<<"\n\n\n";
	cout<<setw(45)<<"GradeReport";
	cout<<"\n\n";
	cout<<setw(20)<<"Test#"<<setw(25)<<"Test Score";
	cout<<endl;
	
	for(int j=0; j<NumTests; j++)
	{	
	cout<<setw(23)<<j+1<<setw(30)<<TestScoresf[j]<<endl;
	cout<<"\n The Class Average is:\t";
	cout<<fixed<<showpoint<<setprecision(2)<<Avgf<<endl;

	return;
}
}
	//end of program 
I:\TestScores2.cpp: In function `int main()':
I:\TestScores2.cpp:35: error: invalid conversion from `int' to `int*'
I:\TestScores2.cpp:35: error: initializing argument 1 of `float ComputeAverage(int*)'
I:\TestScores2.cpp:36: error: invalid conversion from `int' to `int*'
I:\TestScores2.cpp:36: error: initializing argument 1 of `void PrintResults(int*, float)'
I:\TestScores2.cpp:39: error: no match for 'operator<<' in 'std::cin << NumTestsf'

I:\TestScores2.cpp:40: error: overloaded function with no contextual type information
I:\TestScores2.cpp:41: error: no post-increment operator for type

I:\TestScores2.cpp: In function `void GetData(int*, int&)':
I:\TestScores2.cpp:57: error: `NumTests' undeclared (first use this function)
I:\TestScores2.cpp:57: error: (Each undeclared identifier is reported only once for each function it appears in.)
I:\TestScores2.cpp:59: error: `J' undeclared (first use this function)

I:\TestScores2.cpp:101:1: unterminated comment

Execution terminated


Only looking at syntax: line 33 shouldn't have a semicolon, line 45 has a random open brace, line 88's return statement should be below 89's curly brace
Okay the program will compile now with no errors but when I go to run it the program will not start??
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
   //compiler directives
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;

//constant declarations

//function prototype

void GetData(int TestScoresf[], int& NumTestsf);
float ComputeAverage(int TestScoresf[]);
void PrintResults(int TestScoresf[],float Avgf);

//main body
int main ()
{

//local identifiers
float Average;
int TestScoresf, NumTestsf;
NumTestsf = 0;
float x[NumTestsf];	
//function call
    

	void GetData(int TestScoresf, int NumTestsf);
    float ComputeAverage(int TestScoresf);
	void PrintResults(int TestScoresf,float Avgf);
	
	cout<<"How many test scores do you have to enter?/n";
	for (int i=0; i<NumTestsf; i++)
	cin>> x[i];
	
    
    
	
	{

	return NumTestsf;
}
}

//function definitions

void GetData(int TestScoresf[], int& NumTestsf)
{
    int j;
	
		cout<<"Please enter Test Score #:"<<j+1<<"\t";
		cin>>TestScoresf[j];
		
		while ((TestScoresf[j]>=0)&(j<NumTestsf))
		
            { 
              cout<<"Please enter test score or -1 to exit<<j+1<<:l\t";
              cin>>TestScoresf[j];
              
	          }
	         return;
              }

float ComputeAverage(int TestScoresf[])
          {
	int sum=0;
	float avg;
    int NumTests;
	for(int j=0;j<NumTests;j++)
	{
		sum+= TestScoresf[j];
	avg = float(sum/NumTests);
    }
	return avg;

    }//end function

void PrintResults(int TestScoresf[],float Avgf)
{
     int NumTests;
     
	cout<<"\n\n\n";
	cout<<setw(45)<<"GradeReport";
	cout<<"\n\n";
	cout<<setw(20)<<"Test#"<<setw(25)<<"Test Score";
	cout<<endl;
	
	for(int j=0; j<NumTests; j++)
	{	
	cout<<setw(23)<<j+1<<setw(30)<<TestScoresf[j]<<endl;
	cout<<"\n The Class Average is:\t";
	cout<<fixed<<showpoint<<setprecision(2)<<Avgf<<endl;
}
	return;

}
	//end of program

 
Topic archived. No new replies allowed.