I am really new to c++ just started today. This is my first real program (however useless it is) and i am stuck with one error. I am writing my code on code::blocks using mingGW on windows XP. My error is as following-invalid converion from 'const char*'to 'char'. my code is the following.

#include <iostream>
using namespace std;

int main ()
{
    char password;
    char PASSCODE="mypasscode";
    loop:
    cout << "please enter your password:";
    cin >> password;
    if (PASSCODE==password)
    {
        int number;
        int choice;
        cout << "congrats you logged in succesfully";
        loop1:
        cout << "please enter a number";
        cin >> number;
        if (number!=1)
        {
            cout << "you died, too bad";
            cout << "press 1 to play again press 2 to close the program:";
            cin >> choice;
            if (choice=1)
                goto loop2;
            else
                goto loop1;

        }
        if (number=1)
            {
                cout << "congrats you won";
                goto loop2;
            }

    }
    else
    {
        cout << "please try again";
        goto loop;
    }
loop2:
return 0;
}

i looked at the other posts related to this subject but the code was all to complicated for me to understand a scrap of it.

Edited 5 Years Ago by M1n1m@l1$t: clarification

This is incorrect:

char password;
    char PASSCODE="mypasscode";

Typically you will use for C style strings:

const char *PASSCODE = "mypasscode";

to compare C style strings ( which is an array of characters with a NULL character to signal the end of the string ) you will need to use strcmp().

I'm thinking if you are reading a tutorial it has introduced C style strings in order for you to understand some basics about pointers. It probably also introduced the array, which you will need to use.

Alternatively, there is a C++ "string" class.

Edited 5 Years Ago by pseudorandom21: n/a

1) Replace all instance of 'char' with std::string in your program
2) Don't use 'goto', use conditional loops instead. Imagine there were no 'goto' command, how would you restructure your program accordingly?

This question has already been answered. Start a new discussion instead.