#include <iostream>
#include <string>
#include <istream>
usingnamespace std;
int main()
{
int unitNumber;
string unit;
// request user to input a value to convert with unit name
{
cout << "Value to convert = "; //getting input
cin >> unitNumber >> unit;
if (!(cin >> unitNumber))
{
cout << "Error: You did not enter a recognizable number.\n";
}
elseif (cin && unitNumber < 0);
{
cout << "Error: The input value must be a non-negative value.\n";
}
if (cin >> unit = "")
{
cout << "Error: No unit type provided";
}
}
if (!(cin >> unitNumber))
{
cout << "Error: You did not enter a recognizable number.\n";
}
elseif (cin && unitNumber < 0) // Important: no ; at this point!
{
cout << "Error: The input value must be a non-negative value.\n";
}
cin >> unit;
if (unit.empty())
{
cout << "Error: No unit type provided";
}
Note that
= is always assignment (even within an if clause)
== is comparison.