Created
August 6, 2014 17:37
-
-
Save P1xt/8d56b9c37b307da2fedc to your computer and use it in GitHub Desktop.
CS107 Unit 1 Assessment Problem 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Problem 0.1 | |
* | |
* Electronic parrot: Reads in a float from the user and prints it on | |
* the console. | |
*/ | |
#include <iostream> | |
#include <iomanip> | |
#include <limits> | |
using namespace std; | |
int main() { | |
cout << "Please enter a float: "; | |
float myFloat; | |
while(!(cin >> myFloat)){ | |
cin.clear(); | |
cin.ignore(numeric_limits<streamsize>::max(), '\n'); | |
cout << "Invalid input. Try again: "; | |
} | |
cout << "You entered: "; | |
cout << std::fixed << std::setprecision(3) << myFloat << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment