So I did an assignment for c# and I was wondering if there is a better way to get it done? here are my directions also my code is at the bottom.
In this assignment you're going to Prompt the user for a double for the radius of a circle. You will convert their input to a double and calculate the area based on Pi * radius * radius or Pi r squared. Use Double.TryParse to attempt the conversion from the String value in the readline to the out variable (double) that you'll use for the calculation.
You can find examples of Double.TryParse here: https://msdn.microsoft.com/en-us/library/994c0zb1(v=vs.110).aspx
Keep prompting them for a valid number until they enter one. Then calculate and display the area of their circle.
You will then ask them if they'd like to calculate another (y/n). If they type anything but n and y then keep asking them until they enter y or n. You can use a readline for this or I recommend a readkey.
Y will cause the program to run again, n will cause the program to end. Code for uppercase and lowercase y's and n's.
My Program:
using System;
namespace Assignment2
{
class Program
{
static void
Main(string[] args)
{
string
input;
double
bob;
Console.WriteLine("Please
enter a radius:");
input
= Console.ReadLine();
Double.TryParse(input,
out bob);
bob
= 3.14 * (bob) * (bob);
Console.WriteLine("You
inputted: {0}", bob);
Console.WriteLine("Would
you like to enter another?(y/n): ");
input
= Console.ReadLine();
char
innput = char.Parse(input);
if
(innput == 'y' || innput == 'Y')
{
Main(args);
}
else
if (innput == 'n' || innput == 'N')
{
Console.ReadKey();
}
}
}
}
Program -
using System;
namespace CircleArea
{
class Program
{
static void Main(string[] args)
{
double radius, area;
string input;
Console.WriteLine("Enter Radius: ");
//instead of doing Double.TryParse you can directly use
Convert.ToDouble which will directly covert string to double
radius = Convert.ToDouble( Console.ReadLine());
area = Math.PI * radius * radius;
Console.WriteLine("\nArea of circle: "+area);
Console.WriteLine("Would you like to enter another?(y/n): ");
input = Console.ReadLine();
char innput = char.Parse(input);
if (innput == 'y' || innput == 'Y')
{
Main(args);
}
else if (innput == 'n' || innput == 'N')
{
Console.ReadKey();
}
}
}
}
So I did an assignment for c# and I was wondering if there is a better...
Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...
i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...
==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace M8B { class Magic8Ball { static void Main(string[] args) { string question; Console.WriteLine("I am the Magic 8-ball! Ask me a question and I will give you an answer."); Console.Write("Your question: "); question = Console.ReadLine(); Console.WriteLine("\nLet me part the mists of the time for you."); Random rnd = new Random(); int roll =...
Fix the code using C# shown below to show the repitition as seen
on the example screenshot: (Invalid error must
repeat):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class Program
{
static void Main(string[] args)
{
double num, count = 0;
double Tax = 0.00, ship = 5.00, sum = 0.00;
double grandtotal;
char line;
//Set run =true
bool run=true;
do
{
//read amount of item
Console.WriteLine("What is the amount of item : ");
//read in...
I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...
Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program must allow for the teacher to either enter a predetermined number of scores (e.g. 10 exam scores), to keep allowing them to enter in scores until they are finished. You will need to convert these scores to a percentage then store these in a list. You will perform some calculations on these results and also display the contents of the list (percentage values) back...
So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...
Could anybody give me comment here to help me understand this code? please, I want details comment. thank you in advance using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Framing { class Program { static void Main(string[] args) { Dictionary charEncoding = new Dictionary(); charEncoding.Add("A", "01000111"); charEncoding.Add("B", "11100011"); charEncoding.Add("C", "11000001"); charEncoding.Add("ESC", "11100000"); charEncoding.Add("FLAG", "01111110"); Console.WriteLine("Enter Sequence: "); string input = Console.ReadLine().Trim().ToUpper(); Console.Write("Byte count: " + Convert.ToString((input.Split(' ').Length + 1), 2).PadLeft(8, '0')); foreach (string str in input.Split(' '))...
The statement in the following program is in the incorrect order. Rearrange the statements so that they prompt the user to input the shape type (rectangle, circle, or cylinder) and the appropriate dimension of the shape. The program then outputs the following information about the shape: For a rectangle, it outputs the area and perimeter, for a circle, it outputs the area and circumference; and for a cylinder, it output the volume and surface area. After rearranging the statements, your...
C#, I am getting error placing them all in one file pls set them in the order that all 3 work in one file. Thanks //Program 1 using System; class MatrixLibrary { public static int[,] Matrix_Multi(int[,] a, int [,]b){ int r1= a.GetLength(0); int c1 = a.GetLength(1); int c2 = b.GetLength(1); int r2 = b.GetLength(0); if(r2 != c2){ Console.WriteLine("Matrices cannot be multiplied together.\n"); return null; }else { int[,] c = new int[r1, c2]; for (int i = 0; i <...