r/programmingrequests • • Mar 02 '20
solved C program If Else program that calculates meters 3 places in each direction (from meter up to kilo or milimeter)
I want it to calculate what a meter converts to in a if else system. So I would put in 10 or 70352 meters and it calculates up to kilo so 3 places up (deka hecto then kilometer) or downward up to millimeter. I dont know how to do both math and a if else statement. the program would prompt you to enter a meter value and it would output it in the correct form (10 meters = .1 kilometers)
0
Upvotes
2
u/serg06 Mar 02 '20
There's some information missing. It sounds like you don't understand the requirements yourself.
Have you heard of Rubber Ducky Debugging? It's when you explain a problem in detail to a rubber ducky, and through that process you understand the problem well enough to solve it yourself.
1
u/[deleted] Mar 02 '20
I got it with a lot of help from u/joycem8845
The code is
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
double meterConvert(int n, double val);
double meterConvert(int n, double val){
}
int main(void){
printf("%lf milimeters", meterConvert(-3, input));
}
printf("%lf hectometers", meterConvert(-2, input));
}
printf("%lf decimeters", meterConvert(-1, input));
}
printf("%lf meters", meterConvert(0, input));
}
printf("%lf decameters", meterConvert(1, input));
}
else if (input >= 100 && input<=999) {
printf("%lf hectometers", meterConvert(2, input));
}
else if (input >= 1000) {
printf("%lf kilometers", meterConvert(3, input));
}
}