**Hi there,
I'm new to C++ (bet you guys don't hear that very often!!) and what I'm trying to do, in a console application, is this:
- Ask for a number
- If the user input isn't a valid float, get angry and go back to 1.
- If the user input is a float, take the user input and print it back
- Use a function to print back the number, doubled, on a new line
- Count down from 5 and exit
I have it all apart from the if statement. How do I have the program test for a float and act upon it? I was playing around with goto and a label earlier, but that was just awful.
This is my code so far:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
float doubledNumber;
float x;
float doubler (float operand)
{
doubledNumber = operand * 2;
return doubledNumber;
}
int main()
{
std::cout << "Please enter a number\n";
std::cin >> userInput;
std::cout << "The number you entered is " << userInput << ;
std::cout << "\nThis number, doubled, is ";
std::cout << doubler (userInput);
std::cout << "!\n";
Sleep (1000);
std::cout << "Exiting in 5...";
Sleep (1000);
std::cout << "4...";
Sleep (1000);
std::cout << "3...";
Sleep (1000);
std::cout << "2...";
Sleep (1000);
std::cout << "1...";
Sleep (1000);
return 0;
}
At the moment, if I enter anything that isn't a number, it calculates based on 0.
Thanks in advance for any replies! I know this is basic stuff, but I've always found interacting and discussing with other programmers easier than pounding pages.