Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <ctype.h>
- #include <cmath>
- #include <string>
- #include <iomanip>
- using namespace std;
- double GetValidDouble(string prompt = "",const double MIN = -90, const double MAX = 60);
- double TempConvert(double input);
- void Output(double INPUT[],double CONVERTED_INPUT[],const string WEEKDAYS[]);
- int main ()
- {
- const string WEEKDAYS[] = { "Monday", "Tuesday", "Wednesday", "Thursday",
- "Friday", "Saturday", "Sunday"};
- double CONVERTED_INPUT[6];
- double INPUT[6];
- double validInput = 0.0;
- cout << "TEMPERATURE REPORTER"<< endl <<"=================="<< endl;
- for(int counter = 0;counter <7;counter ++)
- {
- validInput = GetValidDouble("Please Enter Temperature for " + WEEKDAYS[counter]+":");
- INPUT[counter] = validInput;
- CONVERTED_INPUT[counter] = TempConvert(INPUT[counter]);
- }
- system("cls");
- Output(INPUT,CONVERTED_INPUT,WEEKDAYS);
- system("pause");
- }
- void Output(double INPUT[],double CONVERTED_INPUT[],const string WEEKDAYS[])
- {
- cout << "THIS WEEK'S TEMPERATURE REPORT" << endl << "==============================" << endl << endl;
- for(int counter = 0; counter <7;counter++)
- {
- cout << right << setw(10) << WEEKDAYS[counter] << " " << right << setw(10) << CONVERTED_INPUT[counter] <<"\370F" << " " << right << setw(10) << INPUT[counter]<< "\370C"<<endl;
- }
- }
- double TempConvert(double input)
- {
- double convertedInput = 0;
- convertedInput = input * 9 / 5 + 32;
- return convertedInput;
- }
- double GetValidDouble(string prompt,const double MIN, const double MAX)
- {
- double validNumber = 0.0; // holds the user input
- string rubbish; // holds garbage input.
- cout << endl <<prompt << " ";
- cin >> validNumber; // try to get input
- if(cin.fail()) // if user input fails...
- {
- cin.clear(); // reset the cin object
- cin >> rubbish; // cleans garbage from cin.
- // report the problem to the user.
- cerr << "\nInvalid input. Please try again and enter a numeric value.\n";
- // Try again by calling the function again (recursion)
- validNumber = GetValidDouble(prompt);
- }
- else if(validNumber < MIN || validNumber > MAX)// if value is outside range...
- {
- // report the problem to the user.
- cerr << "\nInvalid input. Please try again and enter a value between "
- << MIN << " and " << MAX << ".\n";
- // Try again by call the function again (recursion)
- validNumber = GetValidDouble(prompt);
- }
- return validNumber; // returns a valid value to the calling function.
- }
Advertisement
Add Comment
Please, Sign In to add comment