Being asked to write a program that accept both hours and minutes.
Example 2050 (24hrs format)
1) i only know how to code a program below but how to fool-prove it?? (Example a user can only input hrs from 0 to 23, minutes from 0 to 59) But how to accept both value in one input? Example 2050 << can be seperated into 20 and 50, but has to be 1 time input whereby a user cannot input 20/enter/50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <cstdlib>
#include <fstream>
usingnamespace std;
int main()
{
ofstream purch("PurchaseRecord.txt",ios::app);
int hour,minute;
cout << "Key in your time:";
cin >> hour >> minute;
cout << "Your time is being saved";
purch <<"Hrs:"<<hour<<"Minutes:"<<minute;
}
The C++11 standard added a regular expressions (regex) library.
The regex library can be used for pattern matching and would be an elegant choice for your program.
Unfortunately GCC probably has yet to implement the library, but MSVC (Visual Studio) already has it, from what I remember.
Matched: 0000
Did not match: 2500
Did not match: 2459
Matched: 1337
Matched: 2359
Matched: 01:34
Matched: 23:51
Did not match: 43
Did not match: Hello, World!
Did not match: 11011
Did not match: -1323