Weird error after program finishes execution

The program crashes after it displays the users name for the last time. I inserted a system pause in the for loop where I think the problem is occurring. Any advice is appreciated. 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
/******************************************************************************
Austin
6/16/14
While, For Loop, and Function call in C++
*******************************************************************************/
#include <iostream>
#include <string>
using namespace std;


string getname () 
{
	
string yourname = "";
int temp = 0;

while(temp==0)
{	
cout<< "Please enter your name. \n";
cin.sync();
getline(cin,yourname);
cout<< "Is your name " << yourname << " ? \n" << "Enter 1 for YES and 0 for NO \n";
cin>>temp;
system("cls");
}

return (yourname);

}


string countname(string noOneCares)
{
	int temp =0;
	
	cout<< "Please enter how many times you would like your name displayed. \n";
	cin>>temp;
	
	for (int i=0; i<temp; i++)	{
		cout<< noOneCares << " " << i+1 << "\n";
		system("pause");
	}
	system("cls");
}


int main()
{
	string name = getname();
	countname(name);
	return(0);
}
Function countname() is declared with a return type of string. But it doesn't return anything.

Either declare it with a type of void, or actually return a string from the function, before exiting at line 44.
Last edited on
Thanks!
Topic archived. No new replies allowed.