Question:
Help with a C# question please?
AmonAmarth1989
2009-07-07 22:21:22 UTC
I have this question to do and have no experience with C sharp. Could someone please help me out with this please!!

Write a C# Console application to accept a whole number from the user and display the number, the square of the number and the cube of the number. You must use variables for the calculations, i.e there should be three variables.
Four answers:
anonymous
2009-07-07 23:55:36 UTC
//The following code should work for you.

// You should be able to copy and paste this whole answer

// as all notes including these are commented out.

// You could refine this by ensuring only whole numbers are entered



using System;

namespace SquareCubed

{

class YahooAnswerMath

{

static void Main(string[] args)

{

string InputNumber; // holds the number entered.

int ConvertedInputNumber; // The input string needs to be converted to an integer to do the math

int SquaredNumber, CubedNumber; // declare the variables



// Tell the user to enter a number

Console.WriteLine(" Enter a number");



InputNumber = Console.ReadLine(); // get the number

// Force the Input string to an Integer

ConvertedInputNumber = Convert.ToInt32(InputNumber);



// Do the math

SquaredNumber = ConvertedInputNumber * ConvertedInputNumber;

CubedNumber = ConvertedInputNumber * ConvertedInputNumber * ConvertedInputNumber;



//Display the number entered and the results

Console.WriteLine(" You entered " + InputNumber);

Console.WriteLine(" The number you entered squared = " + SquaredNumber);

Console.WriteLine(" The number you entered cubed = " + CubedNumber);



Console.WriteLine("Hit the enter key to exit this program");

Console.ReadLine();// If you compile you will need this to keep the program from closing

}

}

}





// Hope this helps

// Mark D.
Tech Bourne
2009-07-08 02:46:13 UTC
/*

Hey Dear,

I will provide you the complete code

and with explanation

If you are interested read below a few lines

For the program to be done

1. First of all a number must be provided to the computer

2. Square logic must be given to computer

3. then cube logic

then ask the compiler to calculate the above two method with the given number and display the result

*/

using System;

class Program

{

public static void Main(string[] args)

{

int num; //here int is a data type of integer num is the object declared for int

System.Console.WriteLine("Enter a whole number: ");

num = Convert.ToInt32(Console.ReadLine());

int Square = num * num; //this is the logic used for square

int Cube = num * num * num; //this is the logic used for cube

System.Console.WriteLine("The square of number " + num + " is: " + Square);

System.Console.WriteLine("The cube of number " + num + " is: " + Cube);

}

}
mandeep
2015-08-19 20:05:52 UTC
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
S
2009-07-07 22:32:28 UTC
dude thats so easy, are you trying to cheat on your homework or something? I will help you



intUserInput = strUserInput



intSquare = intUserInput * intUserInput

intCube = intUserInput * intUserInput * intUserInput



then display all that in 3 seperate strings


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...