#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
int x = 1;
if (x == 2)
cout << "it worked";
else if (x == 1)
cout << "Hi what is your name ";
getline (cin, name);
if (name == "mark");
x + 1;
}
What I want to do is' when the user enters there name as mark I want to add 1 to x and so it runs the if (x == 2) part of the code.
Could some one please tell me what I did wrong the code compiles fine but dose not print the if (x == 2).
Your code adds one to x at the end (well, actually it doesn't - I suspect you meant x = x+1;, but you actually wrote x+1;, which does nothing). At the end. Then the program finishes. How do you expect it to suddenly go back to the start?