need help why i can copy word for word instructors code and his runs, and mine wont

copied word for word from online video instruction and i have this problem all the time it wont run, but theirs always does.

Maybe it is a microsoft visual studio error on my part in setting up the type of application or something? If so please direct me to a solution. I am using microsoft visual studio 2017 community edition

I know it is alot, I am fresh with no experience, trying to learn. code is copied word for word. Works on his end.

here are all the errors:

errors:
Severity Code Description Project File Line Suppression State
Error C3861 'system': identifier not found classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 59

Severity Code Description Project File Line Suppression State
Error C2660 'Cat::Init': function does not take 2 arguments classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 56

Severity Code Description Project File Line Suppression State
Error C2065 'endl': undeclared identifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 49

Severity Code Description Project File Line Suppression State
Error C2065 'name': undeclared identifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 49

Severity Code Description Project File Line Suppression State
Error C2065 'cout': undeclared identifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 49

Severity Code Description Project File Line Suppression State
Error C2065 'endl': undeclared identifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 43

Severity Code Description Project File Line Suppression State
Error C2065 'cout': undeclared identifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 43

Severity Code Description Project File Line Suppression State
Error C2447 '{': missing function header (old-style formal list?) classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 34

Severity Code Description Project File Line Suppression State
Error C2143 syntax error: missing ';' before '{' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 34

Severity Code Description Project File Line Suppression State
Error C2146 syntax error: missing ')' before identifier 'na' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 33

Severity Code Description Project File Line Suppression State
Error C2447 '{': missing function header (old-style formal list?) classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 23

Severity Code Description Project File Line Suppression State
Error C2143 syntax error: missing ';' before '{' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 23

Severity Code Description Project File Line Suppression State
Error C2146 syntax error: missing ';' before identifier 'GetName' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 22

Severity Code Description Project File Line Suppression State
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 22

Severity Code Description Project File Line Suppression State
Error C2039 'GetName': is not a member of 'Cat' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 22

Severity Code Description Project File Line Suppression State
Error C2061 syntax error: identifier 'string' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 16

Severity Code Description Project File Line Suppression State
Error C2238 unexpected token(s) preceding ';' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 15

Severity Code Description Project File Line Suppression State
Error C2059 syntax error: '(' classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 15

Severity Code Description Project File Line Suppression State
Error C3646 'GetName': unknown override specifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 15

Severity Code Description Project File Line Suppression State
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 12

Severity Code Description Project File Line Suppression State
Error C3646 'name': unknown override specifier classtest01 c:\users\kingj\desktop\c++ files\classtest01\classtest01.cpp 12



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

class Cat
{
private:
	int age;
	string name;
public:
	int GetAge(); // to define this object / make fxn see below
	string GetName();
	void Init(string na, int ag);
	void Meow();
	void Introduce();

};

string Cat::GetName()
{
	return name;
}

int Cat::GetAge()
{
	return age;
}


void Cat::Init(string na, int ag)
{
	name = na;
	age = ag;
}



void Cat::Meow()
{
	cout << "Meow!" << endl;
}

void Cat::Introduce()
{
	Meow();
	cout << "My name is " << name << " and I'm " << age << " years old." << endl;
}

int main()
{
	//cout << "hello world" << endl;
	Cat cat1;
	cat1.Init("Tom", 8);
	cat1.Introduce();

	system("pause");
	return 0;
}
I mean I understand the lesson at a basic level for what he is trying to explain, and how basic classes work. Just bothers me lesson after lesson not being able to run word for word code.
Last edited on
Your app works fine on VS 2015 CE and on the shell. http://cpp.sh/3yzie
Try to recreate the project. Create an empty folder, save your file as main.cpp and choose File->Project from existing code. Choose Visual C++, the folder, select Console app and hit finish.
It's basically working -- are you sure you didn't change anything? See it in action here https://repl.it/repls/PortlyColorfulResources

The idea behind system("pause"); -- it's a Windows way of making sure the Console that it creates doesn't quickly run and close before you can read it. I changed it to a cin.get();, which should work for multiple platforms. Since you include <iostream> you should have access to the system() command; not sure why you have an error.

The other errors look scarier. Especially make sure you didn't add an extra open bracket or forgot a closing bracket -- if you click to the left or to the right (depending on IDE) of the opening curly brace, does it highlight the corresponding closing brace?

Last edited on
You are awesome! thank you! nothing worse than not being able to move on to another lesson.
@Thomas1965
Topic archived. No new replies allowed.