Question

In: Computer Science

This is from Microsoft Visual C#: An Introduction to Object Oriented Programming by Joyce Farrell (7th...

This is from Microsoft Visual C#: An Introduction to Object Oriented Programming by Joyce Farrell (7th Edition)

The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program.

/*

The program requires the user to guess the number of days it takes to make X amount of money when doubling the value every day.

The starting value is $0.01.

The program indicates if the guess is too high, or too low.

*/

using System;

using static System.Console;

using System.Globalization;

class DebugFive4

{

   static void Main()

   {

      const double LIMIT = 1000000.00;

      const double START = 0.01;

      string inputString;

      double total;

      int howMany;

      int count;

      Write("How many days do you think ");

      WriteLine("it will take you to reach");

      Write("{0 starting with {{1}",

         LIMIT.ToString(C), START.ToString("C", CultureInfo.GetCultureInfo("en-US"));

      WriteLine("and doubling it every day?");

      inputString = ReadLine();

      howMany = Convert.ToInt32(inputString);

      count = 0;

      total = START;

      while(total == LIMIT)

      {

         total = total * 2;

         count = count + 1;

      }

      if(howMany >= count)

         WriteLine("Your guess was too high.");

      else

        if(howMany =< count)

           WriteLine("Your guess was too low.");

        else

           WriteLine("Your guess was correct.");

      WriteLine("It takes 0 days to reach {1}",

         count, LIMIT.ToString("C", CultureInfo.GetCultureInfo("en-US")));

      WriteLine("when you double {0} every day",

         START.ToString("C", CultureInfo.GetCultureInfo("en-US")));

   }

}

Solutions

Expert Solution

Hi,

Please find below code .

using System;

using static System.Console;

using System.Globalization;

class DebugFive4
{
static void Main()
{

const double LIMIT = 1000000.00;
const double START = 0.01;
string inputString;
double total;
int howMany;
int count;

Write("How many days do you think ");
WriteLine("it will take you to reach");
WriteLine(LIMIT.ToString("C"));
WriteLine(START.ToString("C"));
// Please make sure flower brackets are in place.
Write("{0} starting with {1}",LIMIT.ToString("C"),START.ToString("C"),CultureInfo.GetCultureInfo("en-US"));
WriteLine("and doubling it every day?");
// The below line should be Console.ReadLine() to read input from user from console.
inputString = Console.ReadLine();
howMany = Convert.ToInt32(inputString);
WriteLine(howMany);
  
count = 0;
total = START;
WriteLine(total);
  
// Since total is double values will never reach exactly 1000000. so its approxiamtely count days.
// so conditional operator should be <=.
while(total <= LIMIT)
{
Write("Total after each loop: "+total+"\n");
total = total * 2;
count = count + 1;
}
  
if(howMany > count)
WriteLine("Your guess was too high.");
else
{
// Note the conditional operator correctd it should be <= and not =<.
if(howMany < count)
WriteLine("Your guess was too low.");
else if(howMany == count)
WriteLine("Your guess was correct.");
}
Write(count);
WriteLine("It takes {0} days to reach {1}",count, LIMIT.ToString("C", CultureInfo.GetCultureInfo("en-US")));
WriteLine("when you double {0} every day",START.ToString("C", CultureInfo.GetCultureInfo("en-US")));

}

}

output :

Thanks,

kindly upvote.


Related Solutions

Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition....
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition. Ch. 5, page 220. Take snip of program results.
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns. I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
Briefly explain the terms used in object-oriented programming with examples.
Briefly explain the terms used in object-oriented programming with examples.
Classes and Objects are the central of Object Oriented Programming (O.O.P.) This is a style of...
Classes and Objects are the central of Object Oriented Programming (O.O.P.) This is a style of programming that focuses on using objects to design and build many great applications. What is the difference between a class an an instance of the class? Explain what is constructor? What do you call a constructor that accepts no arguments? Explain the "has-a" relationship can exist between classes. Explain what is the "this" keyword? Do the following: Answer the 4 points with only one...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create...
*OBJECT ORIENTED PROGRAMMING* JAVA PROGRAMMING GOAL: will be able to throw and catch exceptions and create multi-threaded programs. Part I Create a class called Animal that implements the Runnable interface. In the main method create 2 instances of the Animal class, one called rabbit and one called turtle. Make them "user" threads, as opposed to daemon threads. Some detail about the Animal class. It has instance variables, name, position, speed, and restMax. It has a static boolean winner. It starts...
C++In Object Oriented Programming, classes represent abstractionsof real things in our programs. We must...
C++In Object Oriented Programming, classes represent abstractions of real things in our programs. We must quickly learn how to define classes and develop skills in identifying appropriate properties and behaviors for our class. To this end, pick an item that you work with daily and turn it into a class definition. The class must have at least three properties/data fields and three functions/behaviors (constructors and get/set functions don’t count). Do not pick examples from the textbook and do not redefine...
OBJECT ORIENTED PROGRAMMING Design two grid based games or two block based games in c++ In...
OBJECT ORIENTED PROGRAMMING Design two grid based games or two block based games in c++ In some cases, the bulk of the project lies in producing a nice user interface, probably using the FLTK graphical library, while the algorithmic content is quite simple. In other cases, the bulk of the work is in devising and implementing the algorithms. Some projects are more difficult than others, but a good policy is to choose one which allows extensibility if you have more...
summer/** * This Object-Oriented version of the "Summer" class * is a simple introduction to constructors...
summer/** * This Object-Oriented version of the "Summer" class * is a simple introduction to constructors / * private data members / static vs. not static / and the * "toString" method. * * SKELETON FOR LAB TEST. * * @author Raymond Lister * @version April 2015; */ public class SummerOO { public static int numSummers = 0; // The above variable is used to count the number of // instances of the class SummerOO that have been created. //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT