Chapter 4 exercise 2
You have to add
using static System.Console;
and then you have to put Convert. in front of the ToDouble
So it looks like this, because otherwise it won't run the way they have it in the book: [code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Ch04Ex02
{
class Program
{
static void Main(string[] args)
{
string comparison;
WriteLine("Enter a number: ");
double var1 = Convert.ToDouble (ReadLine());
WriteLine("Enter another number: ");
double var2 = Convert.ToDouble(ReadLine());
if (var1 < var2) comparison = "less than";
else {
if (var1 == var2) comparison = "equal to";
else comparison = "greater than";
}
WriteLine($"The first number is {comparison} the second number.");
ReadKey();
}
|