-3

First time in a computer science class. First lab assignment. Wrote exactly what the teacher wrote, yet it wont compile, and neither the teacher or I can figure out why. Please help. Thank you.

#include <iostream>
#include <string>

using namespace std;

int main ()
{
int number;
string residence;
//Just an example of a comment
cout << "Hello. Welcome to CSCI-1!" endl;
cout << "Spring 2014" endl;

cout << "please enter a number: " endl;
cin >> number;

cout << "you entered the number: " << number <<endl;

cout<<"Please enter your state of residence: " endl;
cin>>residence;
cout <<"you stated you live in " << residence <<"." <<;
return 0;
}

Errors:

lab01.cpp: In function ‘int main()’:

lab01.cpp:11: error: expected ‘;’ before ‘endl’

lab01.cpp:12: error: expected ‘;’ before ‘endl’

lab01.cpp:14: error: expected ‘;’ before ‘endl’

lab01.cpp:19: error: expected ‘;’ before ‘endl’

lab01.cpp:21: error: expected primary-expression before ‘;’ token

2 Answers2

5

You are missing the << operator before the endl constructs. Change

cout << "Hello. Welcome to CSCI-1!" endl;

To

cout << "Hello. Welcome to CSCI-1!" << endl;
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
2

In addition to the missing << before endl (in several lines), you also have an extra one on a line:

cout <<"you stated you live in " << residence <<"." <<;
                                                    ^^ -- extra!

This will cause you to get another compiler error once you fix the first one. It should be:

cout <<"you stated you live in " << residence <<"." << endl;

or

cout <<"you stated you live in " << residence <<".";
Zac Howland
  • 15,777
  • 1
  • 26
  • 42