jeudi 1 octobre 2020

Comparing chars always outputs false, even when it should be true [duplicate]

I'm completely new to coding and i'm trying to make a simple game launcher. The idea is like this:

1    "Game 1"
2    "Game 2"

Where you have to enter the number to open the game.

but whenever i input something it always outputs false even if the input should be true. I don't understand what i'm doing wrong.

Here is the code:

#include <iostream>
#include <string>
#include <stdio.h>
#include <conio.h>
#include <fstream>

using std::cout;
using std::cin;

int main()
{
    char test[100];
    cin >> test;
    cout << test;
    if (test=="1") {
        cout << "Correct!";
    }
    else cout << "Incorrect!";
}

Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire