Arithmetic overflow causing my C++ program .exe to fail

I’m new to C++ and have recently just compiled this temperature converter..
The program compiles just fine within Visual Studio after building and starting without debugging. This is for a class I’m taking and my professor wanted the .exe file so I found it in the project’s ‘debug’ folder.

So I start the program and I input the first temperature and all is fine but then when the second temperature variable comes up ‘celcius = (fahrenheit – 32) * 5.0 / 9.0;’, I get an arithmetic overflow under ‘fahrenheit’. As a result, the program .exe terminates after inputing the second variable.

Any clues as to how I can alleviate this? Thank you. – Kris

#include <iostream> 
using namespace std;



int main() {
    
    float fahrenheit, celcius; 

    cout << "Welcome to Kris' Celcius to Fahrenheit converter!n";  
    cout << "Enter the temperature you would like to convert from Celcius.n";
    cout << "May I suggest to you a balmy 55 degrees?;)n";

    cin >> celcius;
    fahrenheit = (celcius * 9.0) / 5.0 + 32;

    cout << "The temperature in Celcius: " << celcius << endl;
    cout << "The temperature in Fahreheit: " << fahrenheit << endl;
    cout << "Would you like to convert something from Fahreheit to Celcius?n"; 
    cout << "Enter the temperature you'd like to convert here: n";
    
    cin >> fahrenheit; //
    celcius = (fahrenheit - 32) * 5.0 / 9.0; 

    cout << "The temperature in Fahrenheit: " << fahrenheit << endl;
    cout << "The temperature in Celcius: " << celcius << endl;
    cout << "Thank you for using this temperature converter. - Krisn";
    return 0; 

}

Source: Windows Questions C++

LEAVE A COMMENT