p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 (http://p2p.wrox.com/forumdisplay.php?f=798)
-   -   Chapter 4 exercise 2 (http://p2p.wrox.com/showthread.php?t=99655)

markwharveyaprn October 20th, 2017 11:05 PM

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();
}

head_chef January 19th, 2018 01:05 PM

Add this on the top of your code:

using static System.Convert;


All times are GMT -4. The time now is 11:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.