I am reading Programming Principles and Practice using C++.
And one of the exercises is to create a simple mile to kilometer converter, which I did but...
I want to write the program to compensate for "bad input", so in short if someone types a letter value I want something like "please enter a number" to display. I was hoping someone could give me an example of how to do this with the code I have so far or radically correct me if need be with a whole new batch of code.
Below is the (working) code that I have written so far:
[B]#include "std_lib_facilities.h"
int main () {
double mile=1;
double kilo=1.609;
cout<<"Enter miles to convert to kilometers\n";
cin >>mile;
double answer= mile * kilo;
cout<< "That is equal to " << answer << " kilometers"<<"\n";
return 0;
}[/B]
Edited by ZekeDragon, 15 March 2010 - 07:51 AM.
Please use [code] tags.


Sign In
Create Account

Back to top









