converting decimals to binarys

I have written a code but i tried to alter it a little in this manner. But it seemed to not recognise what hexStack.getsize() > 0) is..??

any suggestion pls..


while(hexStack.getSize() > 0)
{
//buffer being a previously declared int
buffer = hexStack.pop();
//if it buffer (last value popped) is greater then 9... enter the switch statement
//to assign it a letter, else just display the number(since it won't need a letter
//representation
if(buffer > 9)
{
switch(buffer)
{
case 10 : cout << "A"; break;
case 11 : cout << "B"; break;
case 12 : cout << "C"; break;
case 13 : cout << "D"; break;
case 14 : cout << "E"; break;
default : cout << "F"; break;
}
}
else
cout << buffer;
}
cout << " in hexadecimal\n";
cout << endl;
return 0;

}
full code pls
#include<iostream>
using namespace std;
#include "stack.h"

int main()
{
int decimal, remainder, choice, base, buffer;
stack s;
cout << "Please enter a decimal: ";
cin >> decimal;
cout << "Convert the number from decimal into:\n0 – Binary\n1 – Octal\n2 – Hexadecimal\n";
cin >> choice;
if(decimal == 0)
{
if(choice >= 0 && choice <= 2)
cout << 0;
else
cout << "Invalid.";
}
if(decimal != 0)
{
switch(choice)
{
case 0:
base = 2;
break;
case 1:
base = 8;
break;
case 2:
base = 16;
break;
default:
cout << "Invalid.";
return 0;
}
}
while(decimal > 0)
{
remainder = decimal % base;
decimal /= base;
s.push(remainder);
}
while(hexStack.getSize() > 0)
{
//buffer being a previously declared int
buffer = hexStack.pop();
//if it buffer (last value popped) is greater then 9... enter the switch statement
//to assign it a letter, else just display the number(since it won't need a letter
//representation
if(buffer > 9)
{
switch(buffer)
{
case 10 : cout << "A"; break;
case 11 : cout << "B"; break;
case 12 : cout << "C"; break;
case 13 : cout << "D"; break;
case 14 : cout << "E"; break;
default : cout << "F"; break;
}
}
else
cout << buffer;
}
cout << " in hexadecimal\n";
cout << endl;
return 0;

}

here you go! :D
would really help if i get any suggestions
Last edited on
sry m8 but i dont got "stack.h" :)
can you give me the sources from it?
for stack you could use
#include<stack>
just one question friend
is there any way or function which i could use to detect floating number and output "invalid".
here is a program for invalid and floating numbers :P
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
float a;
cin>>a;
int checker;
checker=a;
// a=1.2    
if(!cin||((checker+1)!=(a+1)&&(checker-1)!=(a+1))||a==0) // well this
{
cout<<"X"<<endl; 
}




system("PAUSE");
return 0;
}



anyway friend i just dont got the hexstack in my "stack" file
Topic archived. No new replies allowed.