Question

In: Computer Science

The program asks user to enter three integers, and the displays a message indicating whether the...

The program asks user to enter three integers, and the displays a message indicating whether the numbers are in sequential order, in reverse order or in neither order. Find the errors and correct the program codes in the if comparison expressions. (10 points)

1.     using System;

2.     using static System.Console;

3.

4.     class Sorting

5.     {

6.              static void Main()

7.              {

8.                       int num1, num2, num3;

9.                       string snum1, snum2, snum3;

10.                    Write ("Enter first number ");

11.                    snum1 = ReadLine();

12.                    num1 = Convert.ToInt32(snum1);

13.                    Write ("Enter second number ");

14.                    snum2 = ReadLine();

15.                    num2 = Convert.ToInt32(snum2);

16.                    Write ("Enter third number ");

17.                    snum3 = ReadLine();

18.                    num3 = Convert.ToInt32(snum3);

19.                    if (num1 > num2 && num2 <= num3)

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

21.                    else

22.                             if (num1 < num2 && num2 == num3)

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

24.                    else

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

26.           }

27. }

Solutions

Expert Solution

using System;
     using static System.Console;
     class Sorting{
              static void Main()
              {

                       int num1, num2, num3;

                       string snum1, snum2, snum3;
                    Write ("Enter first number ");

                    snum1 = ReadLine();

                    num1 = Convert.ToInt32(snum1);

                    Write ("Enter second number ");

                    snum2 = ReadLine();

                    num2 = Convert.ToInt32(snum2);
                    Write ("Enter third number ");
                    snum3 = ReadLine();

                    num3 = Convert.ToInt32(snum3);
                    // here we have to check the sequence
                    // like num1 should be less than num2 and num2 should be less than num3
                    if (num1 < num2 && num2 < num3)
                             WriteLine ("Numbers are in sequential order");
                    else
                    // here we should check of descending order
                    // num1 should be greater than num2 and num3
                    if (num1 > num2 && num2>num3)
                        WriteLine ("Numbers are in reverse order");
                    else
                        WriteLine ("Numbers are in neither sequential nor reverse order");

           }

}

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
Write a class that asks a user to enter three integers. Display them in ascending and...
Write a class that asks a user to enter three integers. Display them in ascending and descending order. Save the file as Sorting.java Again, Don’t forget to create the application/project  SortingTest.java Class that has the main method and an object to use the Sorting class.
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Write a program that asks the user to enter the name of a file, and then...
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad or another text editor to create a sample file that can be used to test the program. Sample Run java FileLetterCounter Enter file name: wc4↵ Enter character to count: 0↵ The character '0' appears in the file...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Design the logic for a program that allows a user to enter 20 numbers, then displays...
Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. The program is C++. I need a Pseudocode
Write a Java program that asks the user to enter an integer that is used to...
Write a Java program that asks the user to enter an integer that is used to set a limit that will generate the following four patterns of multiples of five using nested loops •Ascending multiples of five with ascending length triangle •Ascending multiples of five with descending length (inverted) triangle •Descending multiples of five with ascending length triangle •Descending multiples of five with descending length (inverted) triangle Use error checking to keep asking the user for a positive number until...
In Python write a program that asks the user to enter the monthly costs for the...
In Python write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile: loan payment, insurance, gas, oil, tires, and maintenance the program should then display the total monthly cost of these expenses, and the total annual cost of these expenses. your program MUST have BOTH a main function AND a function named calcExpenses to calculate the expenses. DO NOT display the expenses inside of the calcExpenses function!!...
Write a program that asks the user to enter an unsigned number and read it. Then...
Write a program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6. COMMENT COMPLETE CODE PLEASE
In a file called LengthSum.java, write a program that: - Asks the user to enter a...
In a file called LengthSum.java, write a program that: - Asks the user to enter a string. - Asks the user to enter a second string. - Prints out the length of the first string, the length of the second string, and the sum of the two lengths, using EXACTLY the same format as shown below. For example: if the user enters strings "UT" and "Arlington", your program output should look EXACTLY like this: Please enter a string: UT Please...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT