Algebra in code and assundry CHAOS
All righty then..... In this lesson we are going to getting down to some hard core numbers. You are given a number of float's and value in them. We are then going to take those Float's and make a program that derives a specific value from those float's making the computer run it through a computation that is provided below.
Here is the situation
Take a look at the code below: it reads a float value, puts it into a variable named x and prints the value of a variable named y.
Your task is to complete the code in order to evaluate the following expression:
Your task is to complete the code in order to evaluate the following expression:
Hints
We expect the result to be assigned to y.
Note: we've prepared a variable containing the value of π. Use it.
Be careful! Watch the operators and keep their priorities in mind. Remember that classical algebraic notation likes to omit the multiplication operator – you need to use it explicitly.
Don't hesitate to use as many parentheses as you need. Keep your code clean and readable – surround the operators with spaces. Use additional variables to shorten the expression.
Hint: multiply x by x to get x squared.
Test your code by using the data we've provided – don't be discouraged by any initial failures. Be persistent and inquisitive. Good luck!
We expect the result to be assigned to y.
Note: we've prepared a variable containing the value of π. Use it.
Be careful! Watch the operators and keep their priorities in mind. Remember that classical algebraic notation likes to omit the multiplication operator – you need to use it explicitly.
Don't hesitate to use as many parentheses as you need. Keep your code clean and readable – surround the operators with spaces. Use additional variables to shorten the expression.
Hint: multiply x by x to get x squared.
Test your code by using the data we've provided – don't be discouraged by any initial failures. Be persistent and inquisitive. Good luck!
The Code
using System;
namespace Parenthesis
{
class Program
{
static void Main()
{
{
float pi = 3.14159265359f;
double y;
Console.Write("Enter value for x: ");
string inputNum = Console.ReadLine();
double x = Convert.ToDouble(inputNum);
// put your code here
Console.WriteLine("After we ran you number through the formula your result is " + y);
}
}
}
}
namespace Parenthesis
{
class Program
{
static void Main()
{
{
float pi = 3.14159265359f;
double y;
Console.Write("Enter value for x: ");
string inputNum = Console.ReadLine();
double x = Convert.ToDouble(inputNum);
// put your code here
Console.WriteLine("After we ran you number through the formula your result is " + y);
}
}
}
}
The results that we are after
Example input 1 Example output y = 0.0949234
Example input -1.5 Example output y = 0.0890702
Example input 12.345 Example output y = 0.101057
Example input -1.5 Example output y = 0.0890702
Example input 12.345 Example output y = 0.101057