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 image 1
when type "john" in window, program still said "your initial name m" instead of "your initial name not m" image 2
, 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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -