|
-
July 24th, 2007, 10:10 AM
#7
Re: C++ Help Please
It's worse than that. I think the body that is supplied is meant to be for main() and that dan isn't meant to be a function, what is more, it looks like dan isn't even meant to be an int, but a string.
I haven't tried compiling it, but try the following:
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string dan = "Dan";
string mystr = "";
cout << "What's your name? ";
getline (cin, mystr);
if (mystr == dan)
{
cout << "My name is" << mystr << "too";
}
cout << "Hello " << mystr << ".\n";
cout << "What is your favorite team? ";
getline (cin, mystr);
cout << "I like " << mystr << " too!\n" << endl;
cout << "My name is Dan and i'm starting using C++!\n" << endl;
cout << "Look forward to see more Programming from me :D.\n" << endl;
return 0;
}
Note that you need to input 'Dan' in order for the comparator to work ('dan' will fail because the string comparator is case sensitive). Also, if you are using namespace std, you do not need to specify 'std::' in front of 'cin', 'cout', 'string' and 'endl' in your program.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|