Max Goddard Max Goddard - 3 years ago 123
C++ Question

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:

#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;
case "A":


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

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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download