Start New Discussion within our **Software Development Community** Not Yet Answered # Square Root and cube Calculation

Discussion Starter mrbrightside10 kplcjl 17 kplcjl 17 Mandeep_1 ddanbe 2,372

0

```
//**Forgot to post the code before:
//**Having problems with the grad square root.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace squarerootsys
{
class Program
{
static void Main(string[] args)
{
int
Square,
Cube;
Squareroot;
Console.WriteLine("\tNumber\tSquare\tCube\tSquareroot");
//loop 12 times calculating and displaying values
for (int Number = 1; Number <= 12;
Number++)
{
Square = Number * Number;
Cube = Square * Number;
Squareroot = Math.Sqrt(Number);
Console.WriteLine("\t{0}\t{1}\t{2}\t{3}", Number, Square, Cube, Squareroot);
}// end of calculate and display
Console.ReadLine();
}
}
}
```

0

I'm confused. This is obviously a homework problem. For that, you don't deserve a code answer. You are supposed to produce something like:

Value: 1, Square: 1, Cube: 1, Sqrt: 1

Value: 2, Square: 4, Cube: 8, Sqrt: 1.4142135623731

Value: 3, Square: 9, Cube: 27, Sqrt: 1.73205080756888

Value: 4, Square: 16, Cube: 64, Sqrt: 2

Value: 5, Square: 25, Cube: 125, Sqrt: 2.23606797749979

Value: 6, Square: 36, Cube: 216, Sqrt: 2.44948974278318

Value: 7, Square: 49, Cube: 343, Sqrt: 2.64575131106459

Value: 8, Square: 64, Cube: 512, Sqrt: 2.82842712474619

Value: 9, Square: 81, Cube: 729, Sqrt: 3

Value: 10, Square: 100, Cube: 1000, Sqrt: 3.16227766016838

Value: 11, Square: 121, Cube: 1331, Sqrt: 3.3166247903554

Value: 12, Square: 144, Cube: 1728, Sqrt: 3.46410161513775

Sum of all Sqrt values: 29.2490045916973

I wrote the code to do that in 11 lines. The square and cubes are simple math statements, you just need to know how to calculate them. That's obviously part of your homework. There are equations for finding the N'th root of numbers, but you don't even have to know that fairly advanced mathmatics. The square root is a built-in function of the Math tool. (A built-in part of the system namespace.)

I've probably given you more help than your teacher wanted you to have in order to solve this.

0

My reply was prior to seeing your new post. OK, you know about Math.Sqrt. You didn't define the type of your Sqrt variable. The type you supplied to Sqrt does not match the type it expects. That should be fine, it should automatically convert int to the right type but this is the type of thing that can bite you in the @ss ao you need to know when you are taking the shortcut.

It IS critical you fix your Sqrt variable's type correctly, setting it to int won't cut it. Your logic is missing the variable that caclulates the sum.

Personally, I wouldn't put Console.ReadLine() inside the loop, I would put it right after writing out the sum AFTER the loop has finished.

0

create a program that will calculate the total of four numbers and the average. when finding the total use the += increment and find out average use ++ increment.do not simply divide by 4 and instead use variable increment. The program should ask input from keyboard for 4 numbers and should output the total and average of the number

0

@Mandeep_1 Don't hijack some one elses thread! Start a new thread with shows what you already have done on your homework assignment! Just posting your homework assignment won't get you any help.

Besides, don't think the OP will answer her after 3 years

This article has been dead for over six months. Start a new discussion instead.