#include <iostream.h>
#include <string.h>
int main()
{
char name1[15];
char name2[15];
bool game = false;
int answer = 1;
while (!game)
{
cout << "enter name1 : " ;
cin.getline(name1 , 5);
cin.ignore(80,'\n');
cout << "enter name2 : " ;
cin.getline(name2 , 5);
cin.ignore(80,'\n');
cout << "name1 = " << name1 << endl;
cout << "name2 = " << name2 << endl;
int y = strcmpi(name1 , name2);
if (!y)
{
cout <<"names are identical" << endl;
}
else
{
cout << "names are different" << endl;
}
cout << "do you want to continue? (1=yes ,2=no ):";
cin >> answer;
if (answer == 2)
game = true;
}// end of while
return 0;
}// end of main
this sample code I wrote last year, but i can't figure out how to make it work the way I want.
when I run the above code under vc++ 6.0, the first time it compares the two strings and prints to the screen "identical or "different" message. The second time it does not allow me to put a string in name1?. This code suppose to compare two names inputed via the keyboard and asks if the user want to try again. It could have to do with memory buffer area?any help is appreciated.
#include <string.h>
int main()
{
char name1[15];
char name2[15];
bool game = false;
int answer = 1;
while (!game)
{
cout << "enter name1 : " ;
cin.getline(name1 , 5);
cin.ignore(80,'\n');
cout << "enter name2 : " ;
cin.getline(name2 , 5);
cin.ignore(80,'\n');
cout << "name1 = " << name1 << endl;
cout << "name2 = " << name2 << endl;
int y = strcmpi(name1 , name2);
if (!y)
{
cout <<"names are identical" << endl;
}
else
{
cout << "names are different" << endl;
}
cout << "do you want to continue? (1=yes ,2=no ):";
cin >> answer;
if (answer == 2)
game = true;
}// end of while
return 0;
}// end of main
this sample code I wrote last year, but i can't figure out how to make it work the way I want.
when I run the above code under vc++ 6.0, the first time it compares the two strings and prints to the screen "identical or "different" message. The second time it does not allow me to put a string in name1?. This code suppose to compare two names inputed via the keyboard and asks if the user want to try again. It could have to do with memory buffer area?any help is appreciated.