Invalid Conversion from const char to char

This is the code of the program I'm creating

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>
using namespace std;

struct playercreation
{
char name[20];
int age;
int race;


};

int main(){
//Variables

char maincharname; //Main Charecter's Name.
int maincharage; //Main Charecter's age.
int maincharrace; //Main Charecter's Race Int
char maincharraceN; //Main Charecter's Race Name

//Charecter Creation
cout << "Welcome to the WorldTraveler Text Based Game (v1.0)" << endl;
cout << "Copywrong 2012 Noah Somberg" << endl << endl;
cout << "This is Charecter Creation:" << endl;
cout << "Name your Charecter (Under 50 Charecters)" << endl;
cin >> maincharname;
cout << "Age your Charecter (Under 1000)" << endl;
cin >> maincharage;
cout << "Choose your race (Enter the corosponding number)" << endl;
cout << "1) Human (ZZZzzz...) " << endl;
cout << "2) Elf (Tall imortal warriors) " << endl;
cout << "3) Halfling (Hobbits) " << endl;
cout << "4) Vulcan (The logical choice) " << endl;
cout << "5) Duck (quack) " << endl;
cin >> maincharrace;

if (maincharrace == 1)
maincharraceN = "Human";
else if (maincharrace == 2)
maincharraceN = "Elf";
else if (maincharrace == 3)
maincharraceN = "Halfling";
else if (maincharrace == 4)
maincharraceN = "Vulcan";
else if (maincharrace == 5)
maincharraceN = "Duck";
else
maincharraceN = "Human";






playercreation mainchar = {

maincharname,
maincharage,
maincharraceN
};
cout << "Your Name is " << mainchar.name << endl;
cout << "Your Age is " << mainchar.age << endl;
cout << "Your Race is " << mainchar.race << endl;
return 0;

}

When I run it I get these errors.

44 invalid conversion from `const char*' to `char'
same error for every If statement. Can someone help me with how to fix this?
1
2
3
char maincharraceN;

maincharraceN = "Human";


You are trying to assign the string of characters "human" to the single character variable maincharraceN.
Last edited on
Okay, so to fix that what would i do?

would it be something like this?

char maincharraceN[20]

Use a string:

1
2
3
4
5
6
7
8
9
#include <string>

//...

string maincharraceN;

//...

maincharraceN = "Human";


EDIT:

should probably do that with your name variable as well.
Last edited on
oh. Yeah, should've though of that. Thanks for the help!
Topic archived. No new replies allowed.