Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to write a program to convert a base 10 number to another base. I keep getting an "undefined symbol main in" error. Can someone help me.
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>using namespace std;
void main ( void )
{
int base10Num;
int newBase;
int quotient;
int rem;
cout<<"Enter any whole base 10 Number";
cin>>base10Num;
cout<<"Enter the base you want the base 10 number converted to: ";
cin>>newBase;
do
{
quotient=base10Num/newBase;
rem=base10Num%newBase;
switch(rem)
{
case'10':rem='A';
break;
case'11':rem='B';
break;
case'12':rem='C';
break;
case'13':rem='D';
break;
case'14':rem='E';
break;
case'15':rem='F';
break;
}
cout<<rem<<endl;
base10Num=quotient;
}
while(base10Num!=0)
}
any other suggestions would be very much appreciated! ty

You don't say if you are using MS Visual Studio or what ......
Under Linux, using g++, that code:
1) Needs a semi-colon after the
while(base10Num!=0)
2) main needs to return an int, not void. (Does MS allow this? If so, it is out of spec.)
3) You do not need quotes around the 'case' selectors, so not:
case '10':
but:
case 10:
That should at least eliminate compile errors.
What if I want base 42? How will that work?
Guy

thank you very much for your help, I was using Code Warrior and next time will state that. I got the program to run successfully with your help, thanks again.

using the Dibble Dabble method, you can convert to any base, even base 42. Don't know why you would want to do that, but it would work in this program also, except the conversion of the integer to a letter would not be appropriately figured out. The only bases I really need to convert to is binary and hexadecimal, so I wrote it for that.

![]() |
silent cmd shell from vbs...
|
Batchfile not running as ...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |