Answer to Question #303730 in C++ for wedyan

Question #303730

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




a. (x < 5) ? y = 10 : y = 20;




b. (fuel >= 10) ? drive = 150 : drive = 30;




c. (booksBought >= 3) ? discount = 0.15 : discount = 0.0;

1
Expert's answer
2022-03-01T07:12:32-0500
#include <iostream>

using namespace std;

int main()
{
	//a. (x < 5) ? y = 10 : y = 20;
	int x, y;
	cout << "Please, enter a value of x: ";
	cin >> x;
	if (x < 5)
		y = 10;
	else
		y = 20;
	cout << "y = " << y<<endl;
	
	//b.(fuel >= 10) ? drive = 150 : drive = 30;
	int fuel, drive;
	cout << "Please, enter a value of fuel: ";
	cin >> fuel;
	if (fuel >= 10)
		drive = 150;
	else
		drive = 30;
	cout << "drive = " << drive << endl;

	//c.(booksBought >= 3) ? discount = 0.15 : discount = 0.0;
	float booksBought, discount;
	cout << "Please, enter a value of booksBought: ";
	cin >> booksBought;
	if (booksBought >= 3)
		discount = 0.15;
	else
		discount = 0.0;
	cout << "discount = " << discount << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog