Why is my code not working?!

Im making a program which converts meters into decimeters and then centimeters, and want to show it as for example 3m=30dm=300cm like that but i have no idea why my code is not working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <conio.h>
void main()
{
int x,cm,dm;
printf("Input number in meters!" );
scanf("%d",&x);
dm=x/10;
x=x%10;
cm=x/100;
x=x%100;
printf("%d=%d=%d=",x,dm,cm);
getch();
}


I mean it does but the program doesn't do any math, why?
Last edited on
set main() to return an int: int main()

wrong formulae: dm=x/10; Correct: dm=x*10; x=x%10;???

Correct code:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <conio.h>

int main()
{
     int x,cm,dm;
     printf("Input number in meters!" );
     scanf("%d",&x);
     dm=x*10;
     cm=x*100;
     printf("%d=%d=%d=",x,dm,cm);
     getch();
}


'%'--the modulo operator, returns the reminder of an equation.

int eg=10%3; eg will be 1 because 3 goes into 10 3 times, reminder 1

Hope it HELPS!!!
Last edited on
lol not sure why i put / in there thanks fixed!

Edit: Thanks alot!
Last edited on
not sure why i put / in there

WOW!!!
Topic archived. No new replies allowed.