SQUARE ROOT AND CONDITIONAL SWITCH

Feb 16, 2011 at 11:04pm
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
Feb 16, 2011 at 11:22pm
------------- I mixed square root with squaring a number, ignore my previous post
Last edited on Feb 17, 2011 at 5:10am
Feb 16, 2011 at 11:34pm
Cstorm that is not a square root.
Feb 17, 2011 at 1:10am
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.
Feb 17, 2011 at 1:31am
And also not post this topic multiple times, please.
Feb 17, 2011 at 2:07am
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
Feb 17, 2011 at 2:52am
Topic archived. No new replies allowed.