#include <cstdlib>
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string x; // You're not using a declared variable.
cout << "What's your husbands name? ";
cin >> William; // You're reading input into an undeclared variable.
cout << "Did you know " << mystr << " loves you?\n"; // You're trying to output an undeclared variable.
else // Else without If
cout << "Your not William's wife. \n";
system("PAUSE"); // This whole line is poor style. But we can talk about that later.
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <iostream>
#include <string>
#include <windows.h> // Add this for later use of Sleep(milliseconds).
#define NEWLINE '\n' // I like adding this so that adding new lines are a bit easier to identify later on.
usingnamespace std;
int main()
{
string name; // Change x to name, for simplicity.
cout << "What's your husbands name? ";
cin >> name; // Change William to name, as it is "string name;".
cout << NEWLINE; // For creating that new line.
if (name == "William") // Means, IF user inputs "William", do the following.
cout << "Did you know that " << name << " loves you?"; // Change mystr to name, as it is "string name;".
else // Means, if user inputs something ELSE instead of "William", do the following.
cout << "You're not William's wife.";
cout << NEWLINE; // Another new line.
Sleep(2000); // Pauses for 2 seconds or 2,000 milliseconds. Try to stay away from 'system()' functions.
return EXIT_SUCCESS;
}
I've edited your code and added explanations. I hope this helps and if you need any further explanation on why I changed something, just ask. =)