У меня есть задание, в котором я должен принимать на входе пользователя в виде:Как конвертировать часть массива символов в целочисленной переменной в C
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;
}
Мой вопрос: что бы я сделал, чтобы преобразовать часть массива символов в два раза.
Почему не просто 'scanf ("% lf,% c ", & inint, &in);'? – P0W
Какой формат должен использоваться для ввода? Я предполагаю, например, «30F», но вы не сказали. из предложений до сих пор предполагают, что вход имеет запятую. – lurker
@ P0W Потому что не следует использовать 'scanf()'. –