# Thread: Why this prog crashes?

1. ## Why this prog crashes?

tconverter.c
Code:
```#include <stdio.h>
int choice;

float cels(float x);
float fahr(float x);
float kelv(float x);
int main()
{
float in, out;

while (true){
in = out = 0;
choice = 0;
printf("Wich type of c0nversions do you want to make?\n");

/* The Choice function */
printf("1)Celsius -> Fahrenheit\n");
printf("2)Celsius -> Kelvin\n");
printf("3)Fahrenheit -> Celsius\n");
printf("4)Fahrenheit -> Kelvin\n");
printf("5)Kelvin -> Celsius\n");
printf("6)Kelvin -> Fahrenheit\n");

scanf("%d", choice);
printf("Value: ");
scanf("%f", in);

switch (choice) {
case 1:
out = cels(in);
break;
case 2:
out = cels(in);
break;
case 3:
out = fahr(in);
break;
case 4:
out = fahr(in);
break;
case 5:
out = kelv(in);
break;
case 6:
out = kelv(in);
break;
}

printf("Output: %f\n", out);
}
}

float cels(float x)
{
float f, k;

if (choice == 1){
f = x * 1,8 + 32;
return f;
}
if (choice == 2){
k = x + 273.15;
return k;
}
}

float fahr(float x)
{
float c, k;

if (choice == 3){
c = (x - 32) / 1.8;
return c;
}
if (choice == 4){
k = (x + 459.67) / 1.8;
return k;
}
}

float kelv(float x)
{
float c, f;

if (choice == 5){
c = x - 273.15;
return x;
}
if (choice == 6){
f = x * 1.8 - 459.67;
return f;
}
}```
When I run this prog, it crashes by the first input, why? (BTW, my first serious prog

2. Code:
`scanf("%d", choice);`
The second argument to scanf requires an address. You get the address of the variable by using the address-of operator, &.

3. Thanks mate, didn't see it.

4. While you're at it, you should indent the while loop.
The second scanf statement also requires fixing, as well.