SQUARE ROOT AND CONDITIONAL SWITCH

Hi guyz,
I wanted to write a program to calculate the square root of any number but it wasn't easy with me somebody help me. Also i'm having difficulties with conditional switch case, lets say 2-6 something should happen, 7-10 another thing should happen till default. Thanks
------------- I mixed square root with squaring a number, ignore my previous post
Last edited on
Cstorm that is not a square root.
Do you know that there is a library function for this?
Just use sqrt(number), and be sure to #include<cmath>

If you need help with your switch statements then you should post your code.
And also not post this topic multiple times, please.
For the square root problem you can break it out into it's definition, you need to know the number that when divided into your original gives itself as the answer with no remainder, in other words x * x = y where y is known. Or if your allowed to use the built in math function mentioned earlier just use that.

For your switch case if you only have three states and one of those is default you may be better off just using a loop and if statements, see below (numbers are from your post):

pseudo code:

while (input != default)
{
if(input == 2-6)
{
do stuff;
}
if(input == 7-10)
{
do stuff;
}
}
if(input == default) //this could be put before while loop if you want to short circuit the logic that //way first
{
do stuff;
}


Allen LeVan
UAT Programming Student
Topic archived. No new replies allowed.