Need help with if statement and error messages

Hello everyone, was wondering if you could help me figure out how to do the if statement to show these if the user inputs certain things.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include <iostream>
    #include <string>
    #include <istream>
    using namespace 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";

		}
		else if (cin && unitNumber < 0);
		{
	       cout << "Error: The input value must be a non-negative value.\n";
		}
		if (cin >> unit = "")
		{
			cout << "Error: No unit type provided";
		}
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
		if (!(cin >> unitNumber))
		{
		cout << "Error: You did not enter a recognizable number.\n";

		}
		else if (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.
Topic archived. No new replies allowed.