我有一个作业,我应该以以下形式接受用户的输入:
double, char('C' for Celsius or 'F' for Fahrenheit)
并将其转换为其他温度标度。为了完成这个任务,我编写了这个程序:
该程序
/*
The purpose of these program is to convert a user's input and use it in a tempurate conversion programs.
By Paramjot Singh
Psuedocode:
import all needed files
ask for user's input.
convert user's imput into 2 varibles: a double and a char
if the char is 'c' convert the double to farinhiet
if the char is 'c' convert the double to celius
display the result.
*/
#include <stdio.h>
int main( )
{
char input[7];
printf("Welcome to the Tempurate Conversion Enter a number followed by C or F, depending on if you what to convert a Celuis Temp to Farinheit or vice versa.");
fgets(input, 7, stdin);
/*if (in == 'C' || in == 'c') commnented out code
{
int f = 9 / 5 (inint + 32);
printf("Input ", in, " Output: " f, " F");
}
else (inint == 'F' || inint == 'f')
{
int c = 5 / 9 (inint - 32);
printf("Input ", in, " Output: " c, " C");
}
else
{
printf("I told you to enter c or f. Restart the program.");
} */
/*to test what was entered*/
printf(input);
return 0;
}
我的问题是如何将部分字符数组转换为双精度。