Menu
Coddy logo textTech

Inputs from User

Lesson 9 of 10 in Coddy's Temperature Converter using C++ course.

challenge icon

Challenge

Easy

On the main function, after your current code, add:

  1. Output: Enter your choice (1-6):
  2. Get input from the user and save it in a variable (choice).
  3. Output: Enter the temperature:
  4. Get input from the user and save it in a variable (temperature).

Add new line in between each output

Try it yourself

#include <iostream>
using namespace std;

float celsiusToFahrenheit(float celsius) {
    return (celsius * 9.0 / 5.0) + 32.0;
}

double celsiusToKelvin(double celsius) {
    return celsius + 273.15;
}

double fahrenheitToCelsius(double fahrenheit) {
    return (fahrenheit - 32.0) * 5.0 / 9.0;
}

double fahrenheitToKelvin(double fahrenheit) {
    return (fahrenheit + 459.67) * 5.0 / 9.0;
}

double kelvinToCelsius(double kelvin) {
    return kelvin - 273.15;
}

double kelvinToFahrenheit(double kelvin) {
    return kelvin * 9.0 / 5.0 - 459.67;
}

int main() {
    cout << "Temperature Converter\n";
    cout << "1. Celsius to Fahrenheit\n";
    cout << "2. Celsius to Kelvin\n";
    cout << "3. Fahrenheit to Celsius\n";
    cout << "4. Fahrenheit to Kelvin\n";
    cout << "5. Kelvin to Celsius\n";
    cout << "6. Kelvin to Fahrenheit\n";
    
    return 0;
}

All lessons in Temperature Converter using C++