?Accelerated c++ help!!

Been reading accelerated c++ and typed in this code ,and for some reason. My compiler won't build it. Im using Codeblocks btw incase you was wondering
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
// vector::size
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <ios>

using namespace std;
int main ()
{
cout << "Please enter your first name : ";
string name;
cin >> name;
cout << "Hello, "  << name << "!" << endl;
// ask for and read the midterm and final grades
cout << "Please enter your midterm and final exam grades ";
double midterm, final;
cin >> midterm >> final;
//ask for and read the homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
vector <double> homework;
double x;
//invariant : homework contains all the homework grades read so far
while (cin >> x)
    homework.push_back(x);
//check that the student entered some homework grades
typedef vector<double>::size_type vec_sz;
vec_sz size = homework.size();
if(size === 0) {

    cout << endl << "You must enter your grades. " <<
     "Please try again." << endl;
     return 1;
}
//sort the grades s
sort(homework.begin(), homework.end());
//compute the median homework grade
vec_sz mid = size/2;
double median;
  median = size % 2 == 0 ? (homework[mid] + homework [mid-1]) \ 2
 : homework[mid];
//compute and writhe the final grade
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision (3)
<< 0.2 *midterm + 0.4 * final + 0.4 * median
<< setprecision(prec) << endl;
}

Did you look at the errors your compiler reported?

Syntax errors your compiler should have reported:
Line 30: === is not a valid operator.

Line 37: sort requires the <algorithm> header.

Line 41: \ is not a valid operator.

Also, to narrow where the problem lies, use /* to comment out as much as possible, while still retaining an error.
Topic archived. No new replies allowed.