But it will break if I enter "a" instead of a number... :(
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
You could use setw and setfill functions to avoid that if-statement in your loop. As so:
#include <iostream>
#include <iomanip>
#include <windows.h>
#include <cstdlib>
using namespace std;
int main(){
int minutes;
int seconds;
cin >> minutes >> seconds;
seconds = (minutes*60)+seconds;
cout << setfill('0') << endl;
while(seconds>0){
cout << seconds / 60 << ":" << setw(2) << seconds % 60 << endl;
Sleep(1000);
seconds--;
}
}
mike_2000_17
Posting Virtuoso
2,134 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
But it will break if I enter "a" instead of a number... :(
Well... why would you want to enter "a"?
ben1996123
Junior Poster in Training
82 posts since May 2011
Reputation Points: 10
Solved Threads: 0
>>Well... why would you want to enter "a"?
That's called "fool-proofing a program". Generally, when writing a program that deals with a user (either through console input, command-line input, config-file input, or a GUI), you must assume that the user has an IQ of 0, i.e., that he/she is an absolute imbecile that could be inputting anything and click on all or any buttons. That's often what beta-testing is about, have a user do all sorts of random crap and watch if the program can cope with it.
mike_2000_17
Posting Virtuoso
2,134 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
That's called "fool-proofing a program". Generally, when writing a program that deals with a user (either through console input, command-line input, config-file input, or a GUI), you must assume that the user has an IQ of 0, i.e., that he/she is an absolute imbecile that could be inputting anything and click on all or any buttons. That's often what beta-testing is about, have a user do all sorts of random crap and watch if the program can cope with it.
Hahaha, +1 because it is to the point. ;)
Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239