View Single Post
  #1 (permalink)  
Old October 20th, 2017, 11:05 PM
markwharveyaprn markwharveyaprn is offline
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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();
}
Reply With Quote