This is what I have so far, I haven't corrected the input prompt display, nor the output display of the time into HH:MM:SS
.
Please give me any suggestions on the program. thanks! :mrgreen:
/* Program definition: The program will ask for and read an elapsed time
in the following format: HH:MM:SS. The program will then compute the elapsed
time in seconds and output the result.
Author: Eric Martin
Date: 29, October 2004 */
#include <string>
#include <iostream>
using namespace std;
int main(){
int Usertime, Hours, Mins, Secs, Product1, // declare indentifiers
Product2, TotalSeconds;
cout << "Please enter the number of hours: ";
cin >> Hours;
cout << " " endl;
cout << "Please enter the number of minutes: ";
cin >> Mins;
cout << " " endl;
cout << "Please enter the number of seconds: ";
cin >> Secs;
cout << " " endl;
string Usertime, Hours, Minutes, Seconds;
int FirstC, SecondC, Hours, Mins, Secs;
cin >> Usertime
FirstC = Usertime.find (":",0);
Hours = Usertime.substr(0,FirstC - 0);
SecondC = Usertime.find(":", FirstC + 1);
Minutes = Usertime.substr(FirstC + 1, SecondC - FirstC + 1);
Seconds = Usertime.substr(SecondC + 1, Usertime.size() - SecondC + 1;
int Hours = atoi(Hours.c_str());
int Mins = atoi(Mins.c_str());
int Secs = atoi(Secs.c_str());
Product1 = Hours * 60;
Product2 = (Mins *60) + Product1; // Formulate the user's time into seconds
TotalSeconds = Product2 + Secs;
cout << "There are " << cin TotalSeconds << " total seconds in the given time.";
getch (); //Wrap-up and close
return();
}