Skip to content

Instantly share code, notes, and snippets.

@P1xt
Created August 6, 2014 17:37
Show Gist options
  • Save P1xt/8d56b9c37b307da2fedc to your computer and use it in GitHub Desktop.
Save P1xt/8d56b9c37b307da2fedc to your computer and use it in GitHub Desktop.
CS107 Unit 1 Assessment Problem 1
/* 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