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