It is supposed to take a ceral box measurement in ounces and convert it to metric tons, as well as tell how many boxes it would take to equal a metric ton. Here it is.

#include <iostream>
using namespace std;

double ounces;

cout << "Enter the box weight in ounces and press enter";
cin >> ounces;

double weightInMetricTons, numberOfCerealBoxes;

weightInMetricTons = ounces/35273.92;
numberOfCerealBoxes = 35273.92/ounces;

cout << "The weight in metric tons is/n" 
     << weightInMetricTons << "and it takes/n"
	 << numberOfCerealBoxes << "to equal a metric ton";

For some reason when I hold the mouse over the line that says that weightInMetricTons and numberOfCerealBoxes are doubles, it says that they are both integers, (they are supposed to be doubles). When I hold the mouse over the variable ounces though, it says that it is a double. A double / a double should be a double, right?

The program fails to build. I tried starting at the end, and cutting sections out to see where the problem started, but I got all the way to the beginning so the only lines were:

#include <iostream>
using namespace std;

and it still failed to build. Is this normal, or does that have to be some content in the program for it to actually build. Any answers to these questions would be greatly appreciated.

ShawnCplus commented: Code tags on first post *thumbs up* +7

Recommended Answers

All 5 Replies

The program fails to build most likely because you have no main() function

#include <iostream>
using namespace std;

int main (int argc, char** argv)
{
  // your program here
  return 0; // successful execution
}
commented: Thanks a lot! +0

I'm not seeing a main function anywhere. do you have this code in a main function?

commented: Thanks so much! +0

No that is the whole code. I should probably go learn what a main function is.

http://www.cplusplus.com/doc/tutorial/program_structure/

From this link:

int main ()

This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function.

Stick your code in a main function and try compiling and running it again.

#include <iostream>
using namespace std;


int main ()
{
	double ounces;

	cout << "Enter the box weight in ounces and press enter";
	cin >> ounces;

	double weightInMetricTons, numberOfCerealBoxes;

	weightInMetricTons = ounces/35273.92;
	numberOfCerealBoxes = 35273.92/ounces;

	cout << "The weight in metric tons is/n" 
		 << weightInMetricTons << "and it takes/n"
		 << numberOfCerealBoxes << "to equal a metric ton";
		 
    return 0;
}
commented: Thanks a lot! +0

Thanks I actually think I was at that exact link a few minutes ago. It made my program run and also made my doubles show up as doubles.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.