C++ :: Aufgabe #222
7 Lösungen

Celsius und Fahrenheit Rechner
Anfänger - C++
von Gelöschte Person
- 31.03.2019 um 15:41 Uhr
Schreibe ein Programm das Celsius in Fahrenheit umrechnet und umgekehrt.
Lösungen:

void CalculateTemp::CalcTemp() { cout << "Welche Berechnung soll durchgeuehrt werden ? Fuer Celsius in Fahrenheit 'C', und anders herum 'F'" << endl; char key; cin >> key; if (key == 'C') { cout << "Wie viel Grad Celsius soll umgerechnet werden?" << endl; float cel; cin >> cel; float celInFahr = (cel * 9 / 5) + 32; cout << cel << " Grad Celsiu sind " << celInFahr << " Grad Fahrenheit" << endl; } else if (key == 'F') { cout << "Wie viel Grad Fahrenheit soll umgerechnet werden?" << endl; float fahr; cin >> fahr; float fahrInCel = (fahr - 32) * 5 / 9; cout << fahr << " Grad Fahrenheit sind " << fahrInCel << " Grad Celsius" << endl; } else { cout << "Falsche Eingabe!"; } }

#include <iostream> using namespace std; int main() { char v; double wa = 0, we = 0; cout << "Please write C to convert in Celsius or F for Fahrenheit \n" ; cin >> v; cout << "Please write your temperature\n"; cin >> wa; switch (v) { case 'C': we = (wa-32)*5/9; //Fahrenheit -> Celsius cout << we << "°C\n"; break; case 'F': we= wa * 9/5 +32; //Celsius -> Fahrenheit cout << we << "°F\n"; break; default: break; } cout << "Press enter to exit"; getchar(); getchar(); }
Konsolenausgabe:
Please write C to convert in Celsius or F for Fahrenheit
F
Please write your temperature
23
73.4°F
Press enter to exit

#include <iostream> using namespace std; int main(){ int x; int y; cout << "Geben Sie in Celsius ein:"; cin >> x >> endl; x = (x*9/5)+32; cout << "es beträgt in Fahrenheit:" << x << endl; cout << "Geben Sie in Fahrenheit ein:"; cin >> y; y = (y-32)*5/9; cout << "es beträgt in Celsius:" << y << endl; return 0; }

#include <iostream> using namespace std; int main() { int celsius=0,fahrenheit=0; cout << "Bitte geben Sie die Temperatur in Celsius ein: "; cin >> celsius; fahrenheit=(0*9/5)+32; cout << celsius << " Celsius sind " << fahrenheit << " Fahrenheit.\n"; return 0; }

#include <iostream> #include "celsius_fahr_cross.h" using std::cout; using std::cin; using std::endl; void celsius_fahr_cross(char yn, float temp) { cout << endl << "Wollen Sie Celsius in Fahrenheit umrechnen? y/n: "; cin >> yn; if(yn == 'y'){ cout << "Temperatur in °C eingeben." << endl; cin >> temp; temp = (temp * 9/5) + 32; cout << endl << temp << "°F"; } else if(yn == 'n'){ cout << "Temperatur in °F eingeben." << endl; cin >> temp; temp = (temp-32) * 5/9; cout << endl << temp << "°C"; } else{ cout << endl << "ERROR" << endl; } }

#include <iostream> #include <cstdlib> #include <locale> using namespace std; int main() { locale::global(locale("German")); double t_celsius = 0; cout << "Temperature in °C: "; cin >> t_celsius; cout <<t_celsius<<"°C = "<<(t_celsius * 9 / 5) + 32 << "°F"<<endl; system("PAUSE"); }

#include <iostream> using namespace std; int main() { int query, input; char c; do { do { cout << "Celsius in Fahrenheit umrechnen (1)\n"; cout << "Fahrenheit in Celsius umrechnen (2)\n"; cout << "Auswahl: "; cin >> query; switch(query) { case 1: cout << "\nCelsius: "; cin >> input; cout << "Fahrenheit: " << (input * 9) / 5 + 32 << "F\n"; break; case 2: cout << "\nFahrenheit: "; cin >> input; cout << "Celsius: " << (input - 32) * 5 / 9 << "C\n"; break; default: cout << "\nFalsche Eingabe\n\n"; } } while(query <= 0 || query > 2); cout << "\nWeitere Umwandlung? (j/n): "; cin >> c; cout << "\n"; } while(c != 'n'); }