IF name = specific name change to nickname

Im developing a small console application that when started will prompt the user for their name.

as a joke to my sister, if her name is entered i want it to change to her nickname

here's my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
  string name;
  cout << "What's your name?" << endl;
  getline (cin, name);
  if(name = 'SistersName')
  {
          (name = 'Sistersnickname')
  }
  else
  {
      (name = name)
  }
  cout << "Nice to meet you " << name << "!" << endl;
  
   
   
    system("PAUSE");
    return 0;


Can anyone tell me where im going wrong?

sorry, the error im getting is this:
12 C:\Users\Neil\Desktop\Programming Projects\First Console no help\whatsyourname.cpp could not convert `(&name)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](110)' to `bool' 
Last edited on
1
2
3
if (name == "SistersName") {
    name = "Sistersnickname";
}


You're using the single '=' sign, which is an assignment operator.

You want to use the double '==' sign, which is the comparison operator.
Hi LimeOats

didnt notice that! but i'm now getting this error

13 C:\Users\Neil\Desktop\Programming Projects\First Console no help\whatsyourname.cpp no match for 'operator==' in 'name == 1701273966' 
You're using single quotes, which are supposed to use for chars.
if(name = 'SistersName')
should be
if(name == "SistersName")
Last edited on
Thank you Jwijnker!
that did it!
Topic archived. No new replies allowed.