Question

Write a program that will accept an integer as input from the user and test if...

  1. Write a program that will accept an integer as input from the user and test if that input is an even number. It should also test if the input is evenly divisible by 6. The program should display “Even” if the user’s input is even. It should additionally display “divisible by 6” if the user’s input is evenly divisible by six.

#include <iostream>

using namespace std;

int main(){

     return 0;

}

  1. Convert the following switch statement to an if- else if – else statement:

int value;             

                  switch (value) {

                                    case 6:

                                                      cout << "The value is 6" << endl;

                                                      break;

                                    case 5:

                                                      cout << "The value is 5" << endl;

                                                      break;

                                    case 4:

                                                      cout << "The value is 4" << endl;

                                                      break;

                                    default:

                                                      cout << "The default was chosen" << endl;

                  } // end of switch() statement

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Answer for first question

#include<iostream>
using namespace std;
int main(){
   int input;
   cin>>input;
   if(input%2 == 0)
       cout<<"Even"<<endl;
   if(input%6 == 0)
       cout<<"divisible by 6"<<endl;
   return 0;
}

//Answer for second question

int value;
if(value==6){
   cout<<"The value is 6"<<endl
}else if(value==5){
   cout<<"The value is 5"<<endl;
}else if(value==4){
   cout<<"The value is 4"<<endl;
}else{
   cout<<"The default value was chosen"<<endl;
}

//If you got the answer, please upvote :)

Add a comment
Know the answer?
Add Answer to:
Write a program that will accept an integer as input from the user and test if...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert the below code into if else selection: #include <iostream> using namespace std; int main() {...

    Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }

  • Could use some help with this, Instructions: You will need to add an input statement for...

    Could use some help with this, Instructions: You will need to add an input statement for the grade variable to this code. Also add a for loop so that you can enter more than one grade. Code the for loop so that at least 7 grades can be entered. #include <iostream> #include <string> using namespace std; void main() {      char grade;           for (int x = 0; x < 7; x++)      {            cout << "Enter a...

  • 4. Write a function that returns a value to the main program illustrated below. In the...

    4. Write a function that returns a value to the main program illustrated below. In the function, the variable passed by the main program needs to be evaluated using a switch statement. The value returned is determined by the case that it matches. (10 points) If value is: return 10 return 20 3 return 30 Anything else, return 0 Main program: #include <iostream> using namespace std; int findValue (int); int main) { Int numb, retvalue cout << "In Enter a...

  • The switch Statement C++program This lab work with the switch statement. • Remove the break statements...

    The switch Statement C++program This lab work with the switch statement. • Remove the break statements from each of the cases. What is the effect on the execution of the program? • Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output. Sample Run: What grade did you earn in Programming I? YOU PASSED! An A - excellent work! The following is...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • c++ : Complete the following program so that it reads an integer. // If the input...

    c++ : Complete the following program so that it reads an integer. // If the input is a digit 0-9, display out the name of the digit, // and the word UNKNOWN for all other values. #include <iostream> using namespace std; int main() { int a, b, c, d, max; cout << endl; return 0; // DO NOT DELETE. }

  • Find the errors in following program. //This program uses a switch statement to assign a //...

    Find the errors in following program. //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score. #include <iostream> uisng namespace std; int main() { int testScore; cout<<"Enter your test score and I will tell you\n"; cout<<"the letter grade you earned: "; cin>>testScore; switch (testScore) { case (testScore < 60) cout<<"Your grade is F.\n"; break; case (testScore <70) cout<<"Your grade is D.\n" break; case (testScore <80) cout<<"Your grade is...

  • Find the errors in following program.   //This program uses a switch statement to assign a...

    Find the errors in following program.   //This program uses a switch statement to assign a // letter grade (A, B, C, D, or F) to numeric test score.     #include <iostream> uisng  namespace std;   int main() {                         int testScore;                         cout<<"Enter your test score and  I will tell you\n";             cout<<"the letter grade you earned: ";             cin>>testScore;               switch (testScore)             {                         case  (testScore < 60)                                     cout<<"Your grade is F.\n";...

  • Looking for help understanding how this example program flows and works. Can you write comments next...

    Looking for help understanding how this example program flows and works. Can you write comments next to each line of code explaining what it does? Why does it use a switch? why not set the roman numerals as constants instead of a switch? Thank you!! //CPP program for converting roman into integers #include <iostream> #include <fstream> #include<cctype> #include<cstdlib> #include<string.h> using namespace std; int value(char roman) { switch(roman) { case 'I':return 1; case 'V':return 5; case 'X':return 10; case 'L':return 50;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT