Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ program that asks the user to enter a time in the format HH:MM, then the program will tell if the time is

Write a C++ program that asks the user to enter a time in the format HH:MM, then the program will tell if the time is a lucky time or just a normal time. And then, if the time carries a specific meaning, as described above, the corresponding meaning will be displayed along. Input validation: Don't accept unreasonable time, or junk values, which must be rejected and asked for another one. This is my code right now, Im having trouble in the input validation part too see if there arent any junk values . Dont know the proper way to scan my string to see if there are values that can't be converted into int.

The Code:

#include #include #include #include

using namespace std;

/* * */ int main() { char again; bool foundFlag; //signal invalid entry int len; //length of input value while(again != 'n'){ int hrs, mins, hr1, hr2 , min1 , min2; string hours, minutes; cout <<"Enter a time (HH:MM): "; getline(cin, hours,':'); getline(cin,minutes, ' '); //traverse through to the end of the input value to find illegal characters for(int i =0; i < len; i++){ // len is the length of input string if(hours[i] == ' ')// space was not allowed - like 1 :56 { cout <<" space was not allowed. "; foundFlag = true; break; // end and get out of the loop } } stringstream (hours) >>hrs; stringstream (minutes) >> mins; if( hrs < 1 && mins <1 ){ cout <<" error!!! this numbers are not accepted! please try again!"; } hr1 = hrs >

cout << "Do you want to run this program again(y/n): "; cin >> again; //if programmer input y the while loop continue / if n is inputed while loop will end if(again == 'y') continue; } cout <<" Programmer: Francisco Gallego"; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions