Max Goddard
Max Goddard

Reputation: 77

Value of type 'const char[2]' is not implicitly convertible to 'int' ERROR C++

I'm writing a quick program to re-familiarise myself with C++ but I get the title error on my switch(choice){case "A": break;} line.

[Value of type 'const char[2]' is not implicitly convertible to 'int']

If anyone could help me understand why I get this error and how to rectify it, would be greatly appreciated. Thank you!

Image of Error: https://i.sstatic.net/n8Cpl.jpg

#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

char printMenuChoice(char choice);

void printSpace(){
    cout << endl;
}

int main(){
    //Print Menu Choice
    char choice;
    choice = printMenuChoice(choice);
    cout << "Choice is " << choice << endl;
    switch(choice){
        case "A":

            break;
    }
    //Attack
    //Chop
    //Shop
    //Stats
    //Exit
}

char printMenuChoice(char choice){
    cout << "[]--- Welcome to Quick Quests ---[]" << endl;
    printSpace();
    cout << "Attack <A>" << endl;
    cout << "Chop   <B>" << endl;
    cout << "Shop   <C>" << endl;
    cout << "Exit   <E>" << endl;
    printSpace();
    cout << "Input Your Choice: ";

    printSpace();
    cin >> choice;
    choice = toupper(choice);
    return choice;
}

Upvotes: 1

Views: 3955

Answers (1)

ypnos
ypnos

Reputation: 52427

You are using a char* (string) literal instead of a char literal. Use case 'A': instead.

Upvotes: 3

Related Questions