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.
#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;
}
Comments
Leave a comment