Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Please i need help debugging the code below. I am suppose to produce a code using functions that converts binary numbers to decimal or octal. I keep getting error at the switch statement "error too few argument in function call".

#include <iostream.> 

long int menu();
long int toDeci(long int);
long int toOct(long int);

using namespace std;

int main () 
{
int convert=menu();

switch (convert)
{
case(0):
    toDeci();
    break;
case(1):
    toOct();
    break;
    }
return 0;
}
long int menu()
{
int convert;
cout<<"Enter your choice of conversion: "<<endl;
cout<<"0-Binary to Decimal"<<endl;
cout<<"1-Binary to Octal"<<endl;
cin>>convert;
return convert;
}

long int toDeci(long int)
{

long bin, dec=0, rem, num, base =1;

cout<<"Enter the binary number (0s and 1s): ";
cin>> num;
bin = num;

while (num > 0)
{
rem = num % 10;
dec = dec + rem * base;
base = base * 2;
num = num / 10;
}
cout<<"The decimal equivalent of "<< bin<<" = "<<dec<<endl;

return dec;
}

long int toOct(long int)
{
long int binnum, rem, quot;
int octnum[100], i=1, j;
cout<<"Enter the binary number: ";
cin>>binnum;

while(quot!=0)
{
    octnum[i++]=quot%8;
    quot=quot/8;
}

cout<<"Equivalent octal value of "<<binnum<<" :"<<endl;
    for(j=i-1; j>0; j--)
    {
        cout<<octnum[j];
    }

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

I am suppose to produce a code using functions that converts binary numbers to decimal or octal.

There's no such thing like converting binary numbers to decimal or octal based on numerical representations as

long int toDeci(long int);
long int toOct(long int);

Such functions are completely nonsensical for any semantical interpretation.

Numbers are numbers, and their textual representation can be in decimal, hex, octal or binary format:

dec 42
hex 0x2A
oct 052
bin 101010

are all still the same number in a long int data type.


Using the c++ standard I/O manipulators enable you to make conversions of these formats from their textual representations.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...