This is my first C script, it's a simple Temperature Conversion program.
Problem: It is either with the Pointers or the way I wrote the Order of Operations in the temperature conversion formulas. The program crashes when it attempts to calculate the answer.
Could someone please explain to me what the exact problem is, and explain how to fix this so I avoid making the same mistake in the future?
Code:
#include <stdio.h>
char name[15];
char choice;
int numbercelcius, numberfahreinheit, *pointerc, *pointerf;
int main()
{
printf("Enter your name: ");
scanf("%s",name);
printf("Hello, %s. This program was written in C.\n",name);
printf("It's purpose is to convert fahreinheit to celcius, and vice versa.\n");
while (1==1)
{
printf("So, %s... what would you like to convert?\n",name);
printf("Type '0' for Celcius to Fahreinheit\n");
printf("Type '1' for Fahreinheit to Celcius\n");
scanf("%d",&choice);
if ( choice == 0 )
{
printf("Type in the temperature Celcius: ");
scanf("%d",&numbercelcius);
numbercelcius = *pointerc;
printf("The temperature is ( *pointerc + 32 ) * ( 9 / 5 ) Fahreinheit.\n\n");
}
else if ( choice == 1 )
{
printf("Type in the temperature Fahreinheit: ");
scanf("%d",&numberfahreinheit);
numberfahreinheit = *pointerf;
printf("The temperature is ( *pointerf - 32 ) * ( 5 / 9 ) Celcius.\n\n");
}
}
return 0;
}