本文整理汇总了C++中Temperature::set_celcius方法的典型用法代码示例。如果您正苦于以下问题:C++ Temperature::set_celcius方法的具体用法?C++ Temperature::set_celcius怎么用?C++ Temperature::set_celcius使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Temperature
的用法示例。
在下文中一共展示了Temperature::set_celcius方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
setConsole();
Temperature t;
Helper h;
bool loop1 = true;
bool loop2 = true;
string user_temperature;
string user_temp_scale;
double temperature;
double celcius_temp;
double fahrenheit_temp;
//creating a loop so the application can be used multiple times without restarting it
while (loop1)
{
//get temperature(number) from user
cout << "Please enter the temperature(number)\nyou want to convert, ('q' to quit): ";
cin >> user_temperature;
//see if user wants to quit the application
if (user_temperature == "q" || user_temperature == "Q")
{
loop1 = false;
}
else
{
//check to see if input is numeric or not
if (h.IsNumeric(user_temperature))
{
temperature = h.ConvertToDouble(user_temperature);
//reset loop 2 to true
loop2 = true;
//creating a loop to make user pick a valid option
while (loop2)
{
//get temperature scale from the user
cout << "\nPlease enter the temperature scale your number" << endl
<< "is currently in ('f' for fahrenheit, 'c' for celcius): ";
cin >> user_temp_scale;
//determine which temperature scale the user is using
if (user_temp_scale == "f" || user_temp_scale == "F")
{
//end the loop
loop2 = false;
//set the celcius and fahrenheit values
t.set_celcius(temperature);
t.set_fahrenheit(t.celcius());
//display output
cout << endl << endl << setprecision(2) << fixed << t.fahrenheit() << " degrees Fahrenheit is equal to "
<< t.celcius() << " degrees Celcius\n\n\n";
}
else if (user_temp_scale == "c" || user_temp_scale == "C")
{
//end the loop
loop2 = false;
//set the fahrenheit and celcius values
t.set_fahrenheit(temperature);
t.set_celcius(t.fahrenheit());
//display output
cout << endl << endl << setprecision(2) << fixed << t.celcius() << " degrees Celcius is equal to "
<< t.fahrenheit() << " degrees Fahrenheit\n\n\n";
}
else
{
//if the user entered an invalid option
cout << "\n\t\tINVALID INPUT!\n";
}
}
}
else
{
//if input is not numeric
cout << "\n\t\tINVALID INPUT!\n\n";
}
}