In my C++ program I am trying to have a series of if statements check if a user input is negative, not a number, or is a number. I cannot figure out how to have a statement check if the input is not a number. Here is my code: #include #include using namespace std; int main() { double numberOfShares; bool check2 = true; while (check2) { cout << "Please enter the
Addition of Two Numbers
Adding two numbers in programming is essentially the same as adding two numbers in general arithmetic. A significant difference is that in programming, you need to pay attention to the data type of the variable that will hold the sum of two numbers.
C++
C++ is a general-purpose hybrid language, which supports both OOPs and procedural language designed and developed by Bjarne Stroustrup. It began in 1979 as “C with Classes” at Bell Labs and first appeared in the year 1985 as C++. It is the superset of C programming language, because it uses most of the C code syntax. Due to its hybrid functionality, it used to develop embedded systems, operating systems, web browser, GUI and video games.
In my C++
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double numberOfShares;
bool check2 = true;
while (check2)
{
cout << "Please enter the number of shares: ";
cin >> numberOfShares;
if (numberOfShares <= 0)
cout << "Invalid quantity. Quantity cannot be negative. Please try again." << endl;
else if ("not an number")
{
cout << "Invalid response. Please enter a number." << endl;
}
else
check2 = false;
}
return 0;
}
Step by step
Solved in 2 steps