lundi 17 juin 2019

else not doing what it should?

I am trying to learn c++ and when i try to do else but it isn't working how it should i think

I have tried everything

#include <iostream>
using namespace std;
int main()
{
    char name[50];
    int text;
    int text2;
  cout << "Enter 1-2: ";
  cin >> name;
  string s = name;
  text = atoi(s.c_str());
  if (text == 1) {
      cout << "You selected 1";
  }
  else if (text == 0) {

      cout << "You selected 0";
  }

  else if (text == 3) {

      cout << "You selected 3";

  }

  else {
      cout << "Invalid number";
  }
}

I expected the else to work. but it just outputted the first else if

Aucun commentaire:

Enregistrer un commentaire