shiva asked in Computers & InternetSoftware · 1 decade ago

How can i debug this program? Tried several times but unable to debug it. your help will be highly appreciated?

// Program asks user to enter three integers

// Program displays a message indicating whether the numbers

// are in sequential order

// in reverse order

// or in neither order

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

public class DebugThree2


public static void Main(string[] args)


int num1, num2, num3;

string snum1, snum2, snum3;

Console.WriteLine("Enter first number ");

num1 = Console.ReadLine();

snum1 = Convert.ToInt32(snum1);

Console.WriteLine("Enter second number ");

snum2 = Console.ReadLine();

num2 = Convert.ToInt32(snum2);

Console.WriteLine("Enter third number ");

snum3 = Console.ReadLine();

num3 = Convert.ToInt32(snum3);

if(num1 <= num2 || num2 <= num3)

Console.WriteLine("Numbers are in sequential order");

else if(num1 >= num2){

Console.WriteLine("Numbers are in reverse order");


Console.WriteLine("Numbers are in neither sequential nor reverse order");



3 Answers

  • 1 decade ago
    Favorite Answer

    Your sieve logic looks weak:

    if(num1 <= num2 || num2 <= num3)

    Console.WriteLine("Numbers are in sequential order");

    else if(num1 >= num2){

    First, the sequential order test should require that BOTH conditions you test are true, not just either one.

    Second, the reverse order test is similarly insufficient. Think about the parallels with the sequential order test.

    Also, I'm not a Java expert, but does Console.ReadLine() read in a string or an int? You're storing its input in ints, then doing some conversion to strings that are never used. That doesn't sound right on two levels.

    Hope that helps.

  • Terry
    Lv 5
    1 decade ago

    A general debugging tool is to add extra output statements to see what is going on. I don't know if that is what you need here, though.

    I see two bugs right off. If the first number is greater than the second but the second is less than the third, OR the second is greater than the third but the first is less than the second, you will get a report that the numbers are in order (true or false == true). Also, your check for reverse order completely ignores the third number.

    Source(s): Many years as a professional programmer. Computer consultant.
  • 1 decade ago

    your 1st num1 and snum1 are switched i think

Still have questions? Get your answers by asking now.