Help with decisions please.

Hi there and hello, I am new to C++ and these forums so bare with me please.

The objective of this program is to get a real number from the user between 1 and 100. If the number is less than or equal to 50, then square it. If it is great than 50, to calculate the square root. If the number is outside of the required range, output an error message.

This is what I have came up with so far:
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
31
32
33
34
35
//Wesley P


#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
	//declaring variable
	double num;
	double answer;


	//input
	cout << "Please input a number between 1 and 100.";
	cin >> num;

	//Decision
	if(num > 100 || < 1)
		cout << "Not a valid number." << endl << endl;
	{
		if(num <= 1 && >= 50)
			answer = num*num;
		else 
			answer = sqrt(num);
	}
	//end if

	//output
	cout << "With the number: " << num << endl << endl;
	cout << "The answer with the selected operation is: " << answer << endl << endl;

}//end main 



This could be completely wrong by my professor has not really covered the material needed for this type of program.

As far as the decision, I did a lot of Google searches and gave it my best shot.

-I'm not asking anyone to do my work, I'm asking for what I did wrong.


Thanks!

-Wesley
Your condition statements are incorrect. On each side of the || and && you need valid boolean statements, and < 1 isn't valid. Try instead num > 100 || num < 1, for example, on line 21.

What were you trying to accomplish with the braces on lines 23 and 28? Where they meant to be wrapping an else clause?
@Zhuge

Wow, thank you for pointing that out. I feel so dumb that I couldn't see it myself.

and the braces.. I was receiving a "else without if" error earlier, and I was trying all kinds of things. When I fixed it I just forgot to remove them. I see now they are not necessary. Thank you so much!
Last edited on
Topic archived. No new replies allowed.