#include <stdio.h>
#include <math.h>
long int input;
long int base, exponent;
void convert(long int x,long int y)
{
input = x;
base = y;
while (input > 0){
exponent = floor(log(input)/log(base));
input = input - pow(base, exponent);
}
}
int main(void){
scanf("%d", &input);
scanf("%d", &base);
convert(input, base);
}
I was trying to compile the code above to see if I can convert decimal into different bases, but I get the following error:
assignment2.c(14): error C2143: syntax error : missing ';' before 'type'
I have been struggling for hours, but I have no idea what this is referring to. How can I fix this?
EDIT: this is the whole message
1>------ Build started: Project: assignment2, Configuration: Debug Win32 ------
1>Build started 2012-04-27 오후 5:45:10.
1>InitializeBuildStatus:
1> Touching "Debug\assignment2.unsuccessfulbuild".
1>ClCompile:
1> assignment2.c
1>c:\users\조화수\documents\visual studio 2010\projects\assignment2\assignment2\assignment2.c(14): error C2143: syntax error : missing ';' before 'type'
1> assign2.c
1>c:\users\조화수\documents\visual studio 2010\projects\assignment2\assignment2\assign2.c(13): warning C4244: '=' : conversion from 'double' to 'long', possible loss of data
1>c:\users\조화수\documents\visual studio 2010\projects\assignment2\assignment2\assign2.c(14): warning C4244: '=' : conversion from 'double' to 'long', possible loss of data
1>c:\users\조화수\documents\visual studio 2010\projects\assignment2\assignment2\assign2.c(19): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\users\조화수\documents\visual studio 2010\projects\assignment2\assignment2\assign2.c(20): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.98
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
powandlogexpect double or float. With a cast it works for me:Initially I got an error stating that the compiler couldn’t resolve an ambiguity between various oveloads (on VS 2008)