Need help with a code

Hi guys! Im doing a very simple program that asks for two inputs (2 names) and the program compares if the last names are the same or not.
At school we made the same program - if i paste it to VS it runs perfect, however if i write a new program (which does the same, only the name of the varialbes are changed) it gives meg dozens of error and I have no clue where I gone wrong.
I also uploaded a screenshot from the list of the errors:
http://speedy.sh/KgAPW/picture.PNG

Please help.
Thanks.

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
 #include "stdafx.h"
#include <stdlib.h>
#include <conio.h>
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
using namespace std;

class Names
{
	string name1, name2;
public:
	Names(string one, string two);
	string lastname(string name);
	bool same();
};

Names::Names(string one, string two)
{
	name1=one;
	name2=two;
}

Names::lastname(string name)
{
	int spacePos=name.find(" ");
	return name.substr(spacePos+1,name.length());
}

Names::same()
{
if (lastname(name1)==lastname(name2)) return true;
else return false;
}

int _tmain(int argc, _TCHAR* argv[])
{
	string asd1, asd2;
	cout << "Plese giv me the name of the first person: " << endl;
	cin >> asd1;
	cout << "Plese giv me the name of the second person: " << endl;
	cin >> asd2;
	Names tester(asd1, asd2);
	if (tester.same()) cout << "Same" << endl;
	else cout << "Not the same" << endl;
	_getch;
	return 0;
}

 
this Names::lastname(string name) should be string Names::lastname(string name)

and this Names::same() should be bool Names::same()
1) Names::lastname(string name)std::string Names::lastname(string name) 
Names::same()bool Names::same()
2) use C++ headers: <stdlib.h><cstdlib>; <math.h><cmath>
3) Change Visual studio settings: _tmain() is non-standard and should not be used.
4) Do not use conio.h. It was deprecated when first NT OS was created.
If you still insist, function call is _getch(), not _getch
Last edited on
Thanks guys :)
Topic archived. No new replies allowed.