Today is my second day with <Accerlerated C++>, and so far I've read until chapter three. Below is the code written in the book and as a part of solving the chapter's exercise problem 3-0, I typed and compiled the code. (using vc++ 6.0)
I assumed there would be no problem since the code was written by the authors who are prominent C++ developers.
So I was surprised when the compiler detected seven compilation errors.
I've read the code over and over agained, and looked up MSDN for the errors but I can't seem to figure out what I did wrong.
So here I am, posting my first question asking for help.
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <ios>
#include <string>
#include <vector>
using std::cout; using std::cin;
using std::endl; using std::sort;
using std::string; using std::vector;
using std::streamsize; using std::setprecision;
int main(void)
{
cout << "Please enter your name : ";
string name;
cin >> name;
cout << "Hello, "<< name<< "!"<< endl;
double midterm, final;
cout << "Midterm : "; cin>> midterm;
cout << "Final : "; cin>> final;
cout << "Enter all you homework grades, followed by EOF(ctrl+z) : ";
vector<double> homework;
double x;
while (cin >> x)
homework.push_back(x);
typedef vector<double>::size_type vec_sz;
vec_sz size;
size = homework.size();
if (size == 0)
{
cout<< endl << "You must enter your grades. Please try again." << endl;
return 1;
}
sort(homework.begin(), homework.end());
vec_sz mid = size / 2;
double median = (size % 2 == 0) ? (homework[mid] + homework[mid - 1]) / 2 : homework[mid];
streamsize prec = cout.precision();
cout << "Your final grade is" << setprecision(3)
<< 0.2 * midterm + 0.4 * final + 0.4 * median << setprecision(prec) << endl;
return 0;
}
-----------------Configuration: ex3_0 - Win32 Debug--------------------
Compiling...
ex3_0.cpp
error C2653: 'vector<double,class std::allocator<double> >' : is not a class or namespace name
error C2146: syntax error : missing ';' before identifier 'vec_sz'
error C2065: 'vec_sz' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'size'
error C2065: 'size' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'mid'
error C2065: 'mid' : undeclared identifier
Error executing cl.exe.ex3_0.obj - 7 error(s), 0 warning(s)
These are the error messages I got.
I'm thinking if the first error is solved the rest will be gone.
But, how can I debug error C2653?