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.
/******************************************************************************
Austin
6/16/14
While, For Loop, and Function call in C++
*******************************************************************************/
#include <iostream>
#include <string>
usingnamespace 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);
}