visual c++ - if/else statement doesn't work c++ -
i'm new programming , code.
#include <iostream> using namespace std; int main(int argc, char** argv) { char name[50]; cout << "please enter name : " << endl; cin >> name; if (name[0] = 'm') { cout << "your initial name m" << endl; } else { cout << "your initial name not m" << endl; } system("pause"); return 0; } when run code, typed "mark" in window , program said "your initial name m".that works fine 
when type "john" in window, program still said "your initial name m" instead of "your initial name not m" 
, wondering why.are there missing in code? time.
if (name[0] = 'm') should have be
if (name[0] == 'm') = used assignment operator. assign m name[0].
use == compare value.
= assign value right hand side left hand side.
== compare value of right hand side left hand side.
Comments
Post a Comment