Hi,
Im trying to make a program that gathers a kelvin temp, changes it to either celcius/fahrenheight then determines the state of a sample of water (gas, solid, liquid)
When I wrote this program out the first time i couldnt get it to work, so i kept on altering it and altering it and now i just cant even think :/ can anyone look over my code and help me straighten out a few things? it says there is 1 error and some warnings but I know there is lots wrong
thanks.
Code:
/*Prac7prog1*/
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
double readnumber()
{
char ch[10];
double input;
printf("\n");
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
printf("°°°°°°° Enter a temperature in Kelvin: °°°°°°°");
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
fflush(stdout);
fgets(ch,sizeof ch,stdin);
input=atof(ch);
return(input);
}
int temptype()
{
char ch[10];
char option;
do {
printf(" ****** Select Which option do you wish view ****** ");
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
printf("°° Enter 'F' for Fahrenheit or 'C' for Celicus: °°");
printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");
option=getch();
option=tolower(option);
}while(!((option == 'f')||(option == 'c')));
scanf("%c\n",option);
return(option);
}
double fahrenheit(double inpF,char option)
{
if (option == 'f')
{
double inpF
inpF=((9*(input-273))/5)+32;
if (inpF>=212) type = 1;
else if (inpF>=33 && inpF<=211) type = 2;
else if (inpF<=32) type = 3;
return(inpF);
}
}
double celcius(double inpC,char option)
{
if (option == 'c')
{
double inpC
inpC=input-273;
if (inpC>=101) type = 1;
else if (inpC>=1 && inpC <= 100) type = 2;
else if (inpC<=0) type = 3;
return(inpC);
}
}
int Main(void)
{
double input=0.0, type;
char option, opt;
printf("This program checks to see whether a temperature is in Gas, Liquid or Solid state");
do
{
printf("\n\nDo you wish to continue? (y/n): ");
do
{
opt = getch();
opt = tolower (opt);
}while (!((opt=='y')||(opt=='n')));
printf("%c\n",opt);
if (opt=='y')
input = readnumber();
option = temptype();
switch (type)
{
case 1:
printf("\nThe state of the water is: Gas, at %.0f degrees Celsius.\n", input);
break;
case 2:
printf("\nThe state of the water is: Liquid, at %.0f degrees Celsius.\n", input);
break;
case 3:
printf("\nThe state of the water is: Solid, at %.0f degrees Celsius.\n", input);
break;
case 4:
printf("\nThe state of the water is: Gas, at %.2f degrees Fahrenheit.\n", input);
break;
case 5:
printf("\nThe state of the water is: Liquid, at %.2f degrees Fahrenheit.\n", input);
break;
case 6:
printf("\nThe state of the water is: Solid, at %.2f degrees Fahrenheit.\n", input);
break;
}
}
while (opt!='n');
return(0);
}