computer science hw

profile47290v3o0
example_2.txt

//Lab Assignment #6, part 3: Time Conversion //Program Name: lab6Part3 //Purpose of the program: converts time from military format to civilian format //Authors: Wei Zhou and Shouwen Wang //Date: 02/19/2016 #include<iostream> #include <string> using namespace std; // get input time int enterTime(int totalTime, int& hrVal, int& minVal) { cout << "please enter a military time(a value between 0000 and 2359) : "; cin >> totalTime; while (totalTime > 2359 || totalTime < 0) { cout << "Error: you entered an invalid time. Try again." << endl; cout << "please enter a military time(a value between 0000 and 2359) : "; cin >> totalTime; } return totalTime; } //perform conversion int ConvHrMin(int totalTime, int& hrVal, int& minVal) { if (totalTime <= 1200) { hrVal = totalTime / 100; minVal = totalTime % 100; } else { hrVal = totalTime / 100 - 12; minVal = totalTime % 100; } return hrVal, minVal; } //display results void finalOutput(){ int totalTime = 0; int hrVal; int minVal; string morning; string noon; morning = "AM"; noon = "PM"; totalTime = enterTime(totalTime, hrVal, minVal); hrVal = ConvHrMin(totalTime, hrVal, minVal); minVal = ConvHrMin(totalTime, hrVal, minVal); if (totalTime <= 1200) { cout << "Time in civilian format£º " << hrVal << ':' << minVal << " " << morning << endl; } else { cout << "Time in civilian format£º " << hrVal << ':' << minVal << " " << noon << endl; } } int main() { cout << "Time Converter" << endl; cout << "--------------" << endl; finalOutput(); cout << endl; return 0; }