Dealing with Functions

I am trying declare and define the functions but I am getting error 'string' was not declared in this scope

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
 #include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

// Function prototype for functions
double inputExam (string examType); 
double inputAndAvgQuizzes();
double inputAndAvgLabs(); 


// main Function 
int main() 
{
	double midterm = 0.0;
	double finalExam = 0.0;
	double labs = 0.0;
	double quizzes = 0.0;
	double grade = 0.0;
	
	
	// Call inputExam ("Midterm") to request the midterm exam grade
	// and return the result to the midterm variable
	
	// Call inputExam ("Final") to request the finalexam grade
	// and return the result to the final variable
	
	// Call inputAndAvgQuizzes () to request and average the two highest quiz grades
	// and return the result to the quizzes
	
	// Call inputAndAvgLabs () to request and average the two highest quiz grades
	// and return the result to the labs variable
	
	//Calculate and display the end of semester grade
	
	midterm = inputExam (string midterm);
	
	finalExam = inputExam (string Final);
	
	labs = inputAndAvgLabs ();
	
	quizzes = inputAndAvgQuizzes ();
	
	grade = ((midterm * .2) + (finalExam * .2) + (labs * .5) + (quizzes * .1)) / 2
	cout << grade << endl;
	
	system("pause");
	return 0;
}

double inputExam (string examType)
{
	double exam;
	cout << "Enter the " examType " Score: ";
	cin >> exam;
	return exam;
}

double inputAndAvgLabs()
{
	double labGrade;
	double labTotal:
	double aveLab;
	int numLabEnt;
	
	cout << "Enter lab grade (Enter -1 to stop): ";
	cin >> labGrade;
	//repeat while when lab not -1
    while (labGrade != -1)
             {
             labTotal = labGrade + labTotal;
             numLabEnt = 1 + numLabEnt;
             
    		 //calculate lab average
    		 aveLab = labTotal/numLabEnt;
    
    		 //enter lab score
             cout << "Enter lab grade (-1 to stop): ";
             cin >> labGrade;
             }//end while
	return aveLab;
}

double inputAndAvgQuizzes ()
{
	double quizGrade;
	double quizTotal:
	double aveQuiz;
	int numQuizEnt;
	
	cout << "Enter quiz grade (Enter -1 to stop): ";
	cin >> quizGrade;
	//repeat while when quiz not -1
    while (quizGrade != -1)
             {
             quizTotal = quizGrade + quizTotal;
             numQuizEnt = 1 + numQuizEnt;
             
    		 //calculate lab average
    		 aveQuiz = quizTotal/numQuizEnt;
    
    		 //enter quiz score
             cout << "Enter quiz grade (-1 to stop): ";
             cin >> quizGrade;
             }//end while
	return aveQuiz;
}
You didn't include the header.

 
#include <string> 


edit:
Also, you need
 
using namespace std;

if you don't qualify references to string, cin and cout with std::
Last edited on
Topic archived. No new replies allowed.