Мой код внизу автоматически округляет вход. Я не вижу никакой функции для округления ввода в любом месте. Может кто-нибудь взглянуть?C++ Auto Rounding
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string input = "";
int weight = 0;
int height = 0;
int bmi = 0;
while (true)
{
cout << "Enter weight: ";
getline(cin, input);
// This code converts from string to number safely.
stringstream myStream(input);
if (myStream >> weight)
break;
cout << "Invalid number, please try again" << endl;
}
while (true)
{
cout << "Enter height: " << endl;
getline(cin, input);
// This code converts from string to number safely.
stringstream myStream(input);
if (myStream >> height)
break;
cout << "Invalid number, please try again" << endl;
}
bmi = height * height;
bmi = weight/bmi;
if(bmi > 25)
{
cout << "Overweight" << endl;
}
else if(bmi < 18.5)
{
cout << "Underweight" << endl;
}
else
{
cout << "Normal weight" << endl;
}
}
Пожалуйста, укажите дополнительную информацию о том, как вы знаете, что вход округлен. – dasblinkenlight
Я занимался вопросом конкуренции, и они предоставили нам примеры ввода и вывода. – nulldev