EXTREMELY NEW TO C++, help!

ok so I've got to make a program that converts centimeters to inches and then converts that amount of inches into the respective yards, feet and inches displayed for the user. When I run my program, I type the amount of centimeters to be calculated and in about a half a second it processes it and closes the window, wtf? so I put a system ("pause"); right before the return 0; and everything runs like it should except it gives me an error, I think thats what it is anyways, which says:

"CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. the "above path" is:

\\acad.dvuadmin.net\sce\HOMEDIR\(my student ID)\Documents\visual studio 2010\projects\part 2, problem 2\part 2, problem 2'

Here's what I've got so far. I've been tinkering with this for two days with no help and I'm getting nowhere, someone please help me out here, where is my mistake?

#include <iostream>
using namespace std;

const double CENT_PER_IN = 2.54;
const int IN_PER_FT = 12, IN_PER_YD = 36;

int main()
{
float cent;
int in,
ft,
yd,
totalinches;

cout << "Enter the centimeter amount to be calculated: " << endl;
cin >> cent;
cout << endl;

cout << "The centimeter(s) you entered is:" << endl;
cout << cent << endl;

totalinches = static_cast <float> (cent) / CENT_PER_IN;
yd = totalinches / IN_PER_YD;
ft = (totalinches - (IN_PER_YD * yd)) / 12;
in = (totalinches % (IN_PER_YD * yd)) - IN_PER_FT;

cout << "Your metric to standard breakdown is: " << endl;

cout << yd << "yards" << endl;
cout << ft << "feet" << endl;
cout << in << "inch(es)" << endl;

system("pause");

return 0;
}
Last edited on
It appears you're running this over the network and your system doesn't support the network path as the working directory for the program. The warning is to let you know, so if for instance you were handling files, using relative paths, you won't be surprised to find they're not using the programs location as the starting point.
You're not doing this, so your program should work well. Also, about system("pause"), check out the discussion at: http://www.cplusplus.com/forum/beginner/1988/
I'm quite alright with being known as a beginner at C++ because I definitely am so I'll continue to use system pause for a while longer. Thank you for the info and the reason for that extra stuff at the end of my program! However, after running this program with different variables input as the centimeter amount, my computed numbers aren't right at all. I used 300 cm to test the program out further instead of the 312cm that I was suppose to use and I started getting negative numbers. Could someone please tell me where I messed up in my calculations part? did I type something backwards? forget to add a part?
The error in calculation is:
in = (totalinches % (IN_PER_YD * yd)) - IN_PER_FT;

First of all revise your use of types and type casting (and format your posts).

Following the logic you've already laid down, i.e.
ft = (totalinches - (IN_PER_YD * yd)) / 12;

You should also use
in = (totalinches - (IN_PER_YD * yd)) % IN_PER_FT;

now, back to
ft = (totalinches - (IN_PER_YD * yd)) / 12;

You've already gone to the trouble of declaring "const int IN_PER_FT = 12", why not use that instead of a magic number?

ft = (totalinches - (IN_PER_YD * yd)) / IN_PER_FT ;
Good point, not sure why I went ahead and put the "12" on the end. I changed the "in" declaration but it when I use the first input variable I have to use(312cm) it still gives me 3 yards, 1 foot, and 2 inches and it should be 3 inches. Do I need to declare "totalinches" as a double or float instead of an int to get it to stop rounding to a whole number?
Last edited on
Topic archived. No new replies allowed.