Hello everyone!
I've just started with c and I think it's really fun! even though I can't do much... I have previous knowledge in a program language called GML, it's not an advanced language, it's about as hard as Javascript.
Anyway I tried to make a fairly short program in c :
#include <iostream>
#include <string>
usingnamespace std;
int main ()
{
int yes ;
string name;
cout << "Stranger: Hello";
cout << "Stranger: What's your name?";
cout <<"\n\nThe stranger who you just met wants to know your name, what should you do?\n\n";
cout <<"type in 1 if you want to tell the stranger your name\nor 0 if you want to run away from that maniac.";
cin >> yes;
if (yes = 1){
cout << "You decide to tell the stranger your name...";
cout << "Stranger: What is your name?";
cin >> name;
cout << name <<":" << " My name is " <<name <<".";
cout << "Okey, It was niec meating you..." << name;
}
if (yes = 0)
{
cout << "You ran away\n";
cout << "blablabla";
cout << "blablablabla";
}
return 0;
}
The following code would probably work in GML with just a few fixes but in c it seems as if the programm ignore the "if (yes=0)" statment. What did I do wrong? and also what should I do to be able to get a string from the player, for example
'=' is assignment. if (yes = 0) means "assign 0 to yes, and then check the result for truthiness". The result is 0, which is implicitly converted to false, so the "if-part" is never executed. Comparisons for equality are done with "==". As for the second question, just change these two lines:
intstring yes ;
if (yes = 1 == "yes")
The language is called C++ by the way. C is a different language.
Please excuse my mistake. The language I'm trying to code in is c++ but I must have forgotten the plusses(facepalm) Anyhow, thanks for the enlightenments :) it made things much clearer now.