cplusplus-training/Teil_1/5. Felder/Uebung 2 - Fahrenheit in Celsius.cpp

42 lines
857 B
C++

#include <iostream>
using namespace std;
const int kEauationVal = 32;
template <class T>
void getVal(const char text[], T *val);
int main()
{
float fahrenheit = 0, schritt_weite = 0, maximal_wert = 0;
float celsiusBuf[10];
cout << "Eingabe\n\n";
getVal("Fahrenheit", &fahrenheit);
cout << "\nAusgabe\n\n";
for (int i = 0; i <10; i++)
{
celsiusBuf[i] = ((fahrenheit+i*10 - kEauationVal) * 5) / 9;
}
for (int i = 0; i <10; i++){
cout<<"Fahrenheit: "<<(fahrenheit+10*i)<<" --> Celsius: "<< celsiusBuf[i]<<endl;
}
return 0;
}
template <class T>
void getVal(const char text[], T *val)
{
do
{
cout << "\t" << text << " = ";
if (cin.fail())
{
cin.clear();
cin.ignore();
}
cin >> *val;
} while (cin.fail() || *val <= 0);
}