0

I'm having a problem with my code. I'm trying to make a program that converts non integer numbers into binary. It returns an error in line 21 saying "invalid conversion from 'const char*' to 'char' [-fpermissive]". What does this mean and how can I solve it?

#include <iostream>

#include <string>

using namespace std;

int main(){

    string number;

    cout<<"Insert number";
    cin>>number;
    int continue = 0, integer;
    bool first = false;
    while(continue >= 0){
        if(primo == false){
            integer = number[continue];
            first = true;
            continue++;
        }
        else{
            char dot = "."; //line 21
            char comma = ",";
            char check = number[continue];
            if((check == comma) or (check == dot)){
                continue = -1;
            }
            else{
                int encapsulation = number[continue]
                integer = (integer*10)+encapsulation;
                continue++;
            }


        }


    }
    cout<<integer;

    return 0;
}

1 Answers1

3

A few mistakes:

  1. continue is a keyword. I renamed it to cont

  2. Double quotes "." is for strings. Chars constants are surrounded by single quotes as '.'.

#include <iostream>

#include <string>

using namespace std;

int main(){

    string number;

    cout<<"Insert number";
    cin>>number;
    int cont = 0; 
    int integer;
    bool first = false;
    bool primo = false;
    while(cont >= 0){
        if(primo == false){
            integer = number[cont];
            first = true;
            cont++;
        }
        else{
            char dot = '.'; //line 21
            char comma = '.';
            char check = number[cont];
            if((check == comma) or (check == dot)){
                cont = -1;
            }
            else{
                int encapsulation = number[cont];
                integer = (integer*10)+encapsulation;
                cont++;
            }


        }


    }
    cout<<integer;

    return 0;
}

Godbolt: https://godbolt.org/z/Tvz3MKxx7

  • 1
    Thanks, the first error of continue is an error of translate, because i writed my program in my language and next i have translate all to english and the name of the variable is change to "continue. The second mistake is my error, thanks for helped me. – Mattia Montemaggi Dec 20 '21 at 17:36