Hello, I need help defining variables. I can't seem to get my code to output the variables in addition to the end-result "volume". Anybody have any tips that could help? Its greatly appreciated. Here is the question that I was assigned.
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 <conio.h> // For function getch()
#include <cstdlib> // For several general-purpose functions
#include <fstream> // For file handling
#include <iomanip> // For formatted output
#include <iostream> // For cin, cout, and system
#include <string> // For string data type
usingnamespace std; // So "std::cout" may be abbreviated to "cout"
int main()
{
float g; //mass in grams
float d; //density in grams/cubic centimeter
float volume;
{
cout << "Please input the mass in grams: ";
cin >> g;
cout << "Please input the density in grams per cubic centimeter: ";
cin >> d;
volume = g / d;
cout << "Volume:" << volume << endl;
}
return 0;
}