Question

Write a C++ Program Rewrite the following expression using an if….else statement (Assume that all variables...

Write a C++ Program

Rewrite the following expression using an if….else statement (Assume that all variables are declared properly)

  1. (x < 5) ? y = 10 : y = 20;
  2. (fuel >=10) ? drive = 150 : drive = 30

Please make two programs for (a) and (b) individually. The first program must include if..else statement for (a), and the second program must include if..else statement for (b).

You must insert the following comments at the beginning of your program and write our commands in the middle:

Write a C++ Program:


/*

// Name: Your Name

// ID: Your ID

*/

#include <iostream>

using namespace std;

int main()

{
         YOUR CODE HERE
}

Homework Answers

Answer #1

/*
// Name: Your Name
// ID: Your ID
*/

#include <iostream>
using namespace std;

int main() {
    int x, y;
    cout << "Enter a value for x: ";
    cin >> x;
    if (x < 5) {
        y = 10;
    } else {
        y = 20;
    }
    cout << "Value of y is " << y << endl;
    return 0;
}

/*
// Name: Your Name
// ID: Your ID
*/

#include <iostream>
using namespace std;

int main() {
    int fuel, drive;
    cout << "Enter a value for fuel: ";
    cin >> fuel;
    if (fuel >= 10) {
        drive = 150;
    } else {
        drive = 30;
    }
    cout << "Value of drive is " << drive << endl;
    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
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...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
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...
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...
Write a program containing a function, reverseDigit, that takes an integer as a parameter and returns...
Write a program containing a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed, then printout the return result. For example, the value of reverseDigit(12345) is 54321; the value of reverseDigit(5600) is 65; the value of reverseDigit(7008) is 8007; and the value of reverseDigit(-532) is -235.    Modify the following program to make a correct output. /* // Name: Your Name // ID: Your ID // Purpose Statement: ~~~ */ #include <iostream>...
In C++ Please, In the main(), below, write a program that uses a switch-statement to choose...
In C++ Please, In the main(), below, write a program that uses a switch-statement to choose between three numbers. The number, choice, should be prompted for and each choice should print out a unique statement. Also, the prompt should continue indefinitely (i.e. keep prompting until the user force-quits the program), and there should be a general catch-all if the user enters other than the three possible choices. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes...
Instructions Write a program that produces the following output: CCCCCCCCC ++ ++ CC ++ ++ CC...
Instructions Write a program that produces the following output: CCCCCCCCC ++ ++ CC ++ ++ CC ++++++++++++++ +++++++++++++++ CC ++++++++++++++ +++++++++++++++ CC ++ ++ CCCCCCCCC ++ ++ Note: The letter C in the output must be uppercase. #include <iostream> using namespace std; int main() {   cout<<"CCCCCCCCC ++ ++ CC ++ ++ CC ++++++++++++++ +++++++++++++++ CC +++++++++++++\n";   cout<<"+++++++++++++++ CC ++ ++ CCCCCCCCC ++ ++";   return 0; } this is my woek #include <iostream> using namespace std; int main() { cout<<"CCCCCCCCC ++...
a)Write an if-else statement with multiple branches. If givenYear is 2100 or greater, print "Distant future"...
a)Write an if-else statement with multiple branches. If givenYear is 2100 or greater, print "Distant future" (without quotes). Else, if givenYear is 2000 or greater (2000-2099), print "21st century". Else, if givenYear is 1900 or greater (1900-1999), print "20th century". Else (1899 or earlier), print "Long ago". Do NOT end with newline #include <iostream> using namespace std; int main() { int carYear = 0; carYear = 1940; /* Your solution goes here */ return 0; }
Analyze the following programs and write down the output of the program. Please print every character...
Analyze the following programs and write down the output of the program. Please print every character (including whitespace character) clearly!       # include <iostream> using namespace std;   int fun( int a ) {       int b = a * 2;       return b;   }   int main()   {       int y = 5;       cout << fun(y) << endl;       cout << fun(-- y) << endl;       cout << fun(y--) << endl;       cout << y <<endl;           return 0;   }
1. Write complete programs. These programs should be able to compile and run. No psuedocode is...
1. Write complete programs. These programs should be able to compile and run. No psuedocode is allowed. No comments are needed. These programs will be graded for syntax, semantics, and programming style. Write a complete program to display the results for the area of a triangle. Formula (1/2) x base x height.   2. Judge the correctness of the following identifiers. Write which are correct and not correct. Please note: that the ‘_’ is an underline character and not a space...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT