Question

Question Rewrite the following C program using switch-case statement. and give me an output please use...

Question

Rewrite the following C program using switch-case statement.

and give me an output please

use printf and scanf

#include<stdio.h>

int main(void) {

     int semester;

    

     printf("What is your Studying Level (1-8)?> ");

     scanf("%d" , &semester);

     if(semester == 1 || semester == 2)

          printf("Your are a freshman!\n ");

     else if(semester == 3 || semester == 4)

          printf("Your are sophomore!\n ");

     else if(semester == 5 || semester == 6)

          printf("Your are junior!\n ");

     else if(semester == 7 || semester == 8)

          printf("Your are senior!\n ");

     else

          printf("You entered wrong level!\n");

         

     printf("< Your name >\n");

     printf("< Your ID >\n");

     return 0;

}

Homework Answers

Answer #1
#include<stdio.h>

int main(void) {

     int semester;

    

     printf("What is your Studying Level (1-8)?> ");

     scanf("%d" , &semester);

    switch(semester){
        case 1:
        case 2:
          printf("Your are a freshman!\n ");
          break;
        case 3:
        case 4:
          printf("Your are sophomore!\n ");
          break;
        case 4:
        case 6:
             printf("Your are junior!\n ");
             break;
        case 7:
        case 8:
            printf("Your are senior!\n ");
            break;
        default:
          printf("You entered wrong level!\n");
    }
         

     printf("< Your name >\n");

     printf("< Your ID >\n");

     return 0;

}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use a Switch statement.A switch statement is just another way of writing an IF statement. The...
Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior. Use character data type for c++. Then you can say something like: char level ='f'; level=toupper(level); You would need a loop for 1 to 5, to test for f, s, j, r and also an illegal grade level. Use a "z" for the illegal grade level Convert...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int...
Write a C++ Program Consider the following incomplete C++ program: #include <iostream> using namespace std; int main() {    …. } Rewrite the program include the following statements. Include the header file fstream, string, and iomanip in this program. Declare inFile to be an ifstream variable and outFile to be an ofstream variable. The program will read data from the file inData.txt and write output to the file outData.txt. Include statements to open both of these files, associate inFile with...
This is my code and can you please tell me why it's not working? By the...
This is my code and can you please tell me why it's not working? By the way, it will work if I reduce 10,000,000 to 1,000,000. #include <iostream> using namespace std; void radixSort(int*a, int n) { int intBitSize = sizeof(int)<<3; int radix = 256; int mask = radix-1; int maskBitLength = 8;    int *result = new int[n](); int *buckets = new int[radix](); int *startIndex = new int[radix]();    int flag = 0; int key = 0; bool hasNeg =...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an...
Please answer the following C question: Read the following files called array-utils5A.c and array-utils5A.h. Build an executable with gcc -Wall -DUNIT_TESTS=1 array-utils5A.c The definitions for is_reverse_sorted and all_different are both defective. Rewrite the definitions so that they are correct. The definition for is_alternating is missing. Write a correct definition for that function, and add unit tests for it, using the unit tests for is_reverse_sorted and all_different as models. Please explain the logic errors present in in the definition of is_reverse_sorted...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
I've just finished typing my code in C, but I don't know how to draw a...
I've just finished typing my code in C, but I don't know how to draw a flowchart. Can somebody help me create a flow chart of this C program please? #include <stdio.h> int main(void){ char answer; // user's inputted single character int score = 0; // initialize score to 0 printf("-----------------------------------\n"); printf("\tMood Self Assessment\n"); printf("-----------------------------------\n"); printf("This Mood Self-Assessment program can help you determine and understand how\nyou are feeling recently."); printf("The user has to answer 3 questions honestly and\ntruthfully in order...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that...
1. Given the following multi-way if statement, provide a switch statement, using proper java syntax, that will provide the same function. Char grade; String tstmsg; if (grade == ‘A’) {   tstmsg = “Excellent”; } else if (grade == ‘B’) {   tstmsg = “Good”; } else if (grade == ‘C’) {   tstmsg = “OK”; } else {   tstmsg = “Study More”; } 2.Write the following for statement as a while statement. for (k = 0; k < 3; k++) {   System.out.println...
Please answer the following C question: Read the files vec5C.h, vec5C.c, and main5C.h. Build an executable...
Please answer the following C question: Read the files vec5C.h, vec5C.c, and main5C.h. Build an executable using gcc -Wall main5C.c vec5C.c Do this: Add function definitions to vec5C.c so that functions are available for dot product, sum, and cross product. Do not change the function prototypes in vec5C.h. Then add code to main to call these functions and display the dot product of u and v, the sum of u and v, and the cross product of u and v....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT