Answer to Question #159550 in C++ for Earl

Question #159550

The formula used to calculate the density of a substance is mass divided by volume. It is expressed as d = m/v. Ask users for the mass and volume of a substance and calculate the density for them.

 

Output:

Enter the mass of a substance in grams (integers only):       [assume user inputs 10]

Enter the volume of a substance in milliliters (integers only):      [assume user inputs 4]

The density of your substance is 2.5


1
Expert's answer
2021-01-31T08:02:53-0500
#include <iostream>
using namespace std;

int main() {
  int mass;
  int volume;
  double density;
  
  cout << "Enter the mass of a substance in grams (integers only): ";
  cin >> mass;
  cout << "Enter the volume of a substance in milliliters (integers only): ";
  cin >> volume;
  density = mass / (double)volume;
  cout << "The density of your substance is " << density;
  
  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