Samppa
02-05-2005, 07:18 PM
Right, I'm new to C++, and I've been having trouble with the following code.
A dumbed down version (especially the if bracket):
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[])
{
char name1[256], name2[256];
cout << "What is your name? "; gets(name1);
cout << "\nWelcome "<< name1 <<endl;
cin.get();
cout << "\nPlease insert your name: ";
cin.getline ( name2, 256 );
cin.get();
if ( name1 == name2 ) {
cout << "\nHi!";
cin.get();
return 0;
}
else {
cout << "\nBye.";
cin.get();
return 0;
}
The part I'm having trouble with is the if bracket. How would I code that if name1 matches name2 it'd say "Hi", and if they didn't match, it'd say "Bye". I've been having trouble with that for the last couple of days. :/
A dumbed down version (especially the if bracket):
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[])
{
char name1[256], name2[256];
cout << "What is your name? "; gets(name1);
cout << "\nWelcome "<< name1 <<endl;
cin.get();
cout << "\nPlease insert your name: ";
cin.getline ( name2, 256 );
cin.get();
if ( name1 == name2 ) {
cout << "\nHi!";
cin.get();
return 0;
}
else {
cout << "\nBye.";
cin.get();
return 0;
}
The part I'm having trouble with is the if bracket. How would I code that if name1 matches name2 it'd say "Hi", and if they didn't match, it'd say "Bye". I've been having trouble with that for the last couple of days. :/