Answer to Question #183001 in C++ for Vincenzo Santoro

Question #183001

Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density.

Format your output to two decimal places.


1
Expert's answer
2021-04-22T12:06:32-0400
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int main(){  


	float mass;
	float density;
	float volume;
	// accepts as input the mass, in grams
	cout<<"Enter the mass in grams: ";
	cin>>mass;
	//density, in grams per cubic centimeters
	cout<<"Enter the density in grams per cubic centimeters: ";
	cin>>density;
	// outputs the volume of the object using the formula: volume = mass / density.
	volume = mass / density;
	//Format your output to two decimal places.
	cout<<"The volume = "<<fixed<<setprecision(2)<<volume<<" cubic centimeters\n";
	system("pause");
	return 0;
}

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
APPROVED BY CLIENTS