I'm a beginner in C++ and I wrote a simple program to study the syntax of C++. The code is going to a response but is wrong. The code is:
// converter_temp1.cpp
// converter 3 temp. celsius, fahrenheit e kelvin
// entrar: temperatura, escala atual e pretendida
#include "stdafx.h"
int main()
{
double t, tempC, tempF, tempk;
std::string sa, sp, cel, fah, kel;
std::cout << "Enter with your temperature, actual and pretend scale, for celsius = cel, fahrenheit = fah and kelvin = kel" << std::endl;
std::cin >> t >> sa >> sp;
if (sa == cel && sp == fah) {
tempF = 32 + (9 * t) / 5;
std::cout << ">>>> Temperature is " << tempF << " F in Fahrenheit!!!! <<<<" << std::endl;
}else {
if (sa == kel && sp == cel) {
tempC = t + 273;
std::cout << ">>>> Temperature is " << tempC << " C in Celsius!!!! <<<<" << std::endl;
}
else {
std::cout << ">>>> Temperature scale wrong!!!! <<<<" << std::endl;
}
}
return 0;
}
The answer of this code is always >>>> Temperature scale wrong!!!! <<<<. Could anyone help me?
Thanks!
Aucun commentaire:
Enregistrer un commentaire