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 C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
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...
c program Write a program that asks the user to enter a sequence of 15 integers,...
c program Write a program that asks the user to enter a sequence of 15 integers, each either being 0, 1, or 2, and then prints the number of times the user has entered a "2" immediately following a "1". Arrays are not allowed to appear in your code. Include ONLY THE SCREENSHOT OF YOUR CODE in an image file and submit the file.
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.
JAVA Write a test program that prompts the user to enter a list and displays whether...
JAVA Write a test program that prompts the user to enter a list and displays whether the list is sorted or not. Here is a sample run. Note that the program first prompts the user to enter the size of the list. Using Array My output should look like this Enter the size of the list: 8 Enter the contents of the list: 10 1 5 16 61 9 11 1 The list has 8 integers 10 1 5 16...
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 C# program using repl.it that asks the user for three integers and prints the...
Write a C# program using repl.it that asks the user for three integers and prints the average value as a double. Example calculation (3 + 6 + 7) / 3 = 5.33333333333333 Given the data above, the output should be similar to: The average for the values entered is: 5.33333333333333 As always comments in your code are expected (what why how etc… ) Submit your repl.it link to the assignment dropbox text submission area.
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...
In.java Write a program that repeatedly asks the user to enter their password until they enter...
In.java Write a program that repeatedly asks the user to enter their password until they enter the correct one. However, after 5 failed attempts, the program "locks out" the user. We will show that with an error message. Assume the password is HOC2141 (case sensitive). Note that there is a special case that is not shown below. To identify it, think of all possible scenarios of input for this program. ----------- Sample run 1: Enter your password: Blake Wrong Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT