Tried an explicit conversion failed:
if ((int)temps[i] < min && (int)temps[i]>0) { min = (int)temps[i]; } The task itself: Write a program that prints a temperature close to 0, among the input data. If two numbers are equally close to zero, a positive integer should be considered closer to zero (for example, if the temperature is -5 and 5, output 5). Do not change the type of input data. Here is the actual code itself:
#include <iostream> #include <string> #include <cstdlib> using namespace std; void min_temp(int n, string temps) { int min = 5526; int min1 = -273; for (int i = 0; i < temps.size(); i++) { if ((int)temps[i] < min && (int)temps[i]>0) { min = (int)temps[i]; } else if ((int)temps[i] < min1 && (int)temps[i] < 0) { min1 = (int)temps[i]; } } if (min > abs(min1)) { cout << min1<<endl; } else cout << min<<endl; } int main() { int n; // the number of temperatures to analyse cin >> n; string temps; for (int i = 0; i <= n; i++) { getline(cin, temps); } min_temp(n, temps); system("pause"); return 0; }