zamiana systemy liczbowe

0

Witam, mam problem, otóż nie wiem czemu program wysypuje mi się, gdy chcę wypisać wynik. To mój kod:

 
#include <iostream>
#include <cstring>
using namespace std;

string liczbahex;
unsigned int ile = sizeof(liczbahex);


void hex2bin(string liczbahex);


int main()
{
    cout << "podaj liczbe hex: ";
    getline(cin, liczbahex);
    cout << "liczba " << liczbahex << " w systemie binarnym to: ";
    cout << hex2bin(liczbahex);

    return 0;
}

void hex2bin(string liczbahex){
    for(unsigned int i = 0; i<ile; i++){
                        if(liczbahex[i] == '0')
                               cout << "0000";
                        else if(liczbahex[i] == '1')
                               cout << "0001";
                        else if(liczbahex[i] == '2')
                               cout << "0010";
                        else if(liczbahex[i] == '3')
                               cout << "0011";
                        else if(liczbahex[i] == '4')
                               cout << "0100";
                        else if(liczbahex[i] == '5')
                               cout << "0101";
                        else if(liczbahex[i] == '6')
                               cout << "0110";
                        else if(liczbahex[i] == '7')
                               cout << "0111";
                        else if(liczbahex[i] == '8')
                               cout << "1000";
                        else if(liczbahex[i] == '9')
                               cout << "1001";
                        else if(liczbahex[i] == 'a')
                               cout << "1010";
                        else if(liczbahex[i] == 'b')
                               cout << "1011";
                        else if(liczbahex[i] == 'c')
                               cout << "1100";
                        else if(liczbahex[i] == 'd')
                               cout << "1101";
                        else if(liczbahex[i] == 'e')
                               cout << "1110";
                        else if(liczbahex[i] == 'f')
                               cout << "1111";
        }
        }
 

Proszę o pomoc:)

0

Przecież funkcja hex2bin() zwraca void. Co ty chcesz zrobić w tej linii cout << hex2bin(liczbahex);??

0

oj, fakt, zauważyłam... wstawiłam to 'cout <<' i dziwię się czemu nie działa. no nic, dziekuję za pomoc:)

1 użytkowników online, w tym zalogowanych: 0, gości: 1