当前位置: 首页>>代码示例>>C++>>正文


C++ Temperature::fahrenheit方法代码示例

本文整理汇总了C++中Temperature::fahrenheit方法的典型用法代码示例。如果您正苦于以下问题:C++ Temperature::fahrenheit方法的具体用法?C++ Temperature::fahrenheit怎么用?C++ Temperature::fahrenheit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Temperature的用法示例。


在下文中一共展示了Temperature::fahrenheit方法的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";
			}
		}
开发者ID:Wizner,项目名称:cplusplus-fall2013,代码行数:83,代码来源:Main.cpp


注:本文中的Temperature::fahrenheit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。