Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
This is the forum to discuss the Wrox book Beginning C# 6.0 Programming with Visual Studio 2015 by Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid; ISBN: 978-1-119-09668-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2017, 11:05 PM
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();
}
 
Old January 19th, 2018, 01:05 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2018
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Add this on the top of your code:

using static System.Convert;




Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 exercise #7 Alan G BOOK: Python Projects 0 December 21st, 2015 10:08 PM
Chapter 4 Exercise 4.2 PLEASE HELP NewbySwaj BOOK: Beginning Visual C# 2012 1 November 25th, 2013 11:49 AM
Chapter 3: exercise 2. tobbeebbot BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 3 September 6th, 2012 11:09 PM
Chapter 4 exercise 4 earlmw BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 0 March 3rd, 2012 03:05 PM
Chapter 4 Exercise 4 Will BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 2 September 18th, 2009 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.