954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

new to C++

Hi, I'm totally new to C++ and so far am extremely confused. I was wondering if anyone could give me any help with one of my assignments. Basically I don't know where to even start. I think if maybe someone can help me get started maybe I can figure this problem out. Anyways, here's the problem...

Write a program that prompts the user to input a length expressed in centimeters. The program should then convert the length to inches and output the length expressed in yards, feet, and inches, in that order. For example suppose the input for centimeters is 312. To the nearest inch, 312 centimeters is equal to 123 inches. 123 inches would thus be output as:
3 yards, 1 foot, and 3 inches.

Any help would be greatly appreciated.

dal4488
Newbie Poster
17 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

Well we dont do homework but here is a basic idea of how you would go about this. first you would need to ask the user to input the length in centimeters using cin. and then you take the info you get and you would then have the program convert centimeters to inches. and from inches its not hard to figure out how many yards, feet and inches that equals :) try to post atleast alittle bit of code next time thanks :)

big_k105
PFO Founder
Team Colleague
357 posts since May 2003
Reputation Points: 36
Solved Threads: 2
 

Thanks for the help...Have I started this off right so far?

#include

using namespace std;

const double conversion = 2.54
const int inchesPerFoot = 12

int main()
{
int centimeters, inches;
int yards, feet;

cout << "Enter length in centimeters: ";
cin >> centimeters;
cout << endl;
cout << "The number entered was " << centimeters
<< " for centimeters. " << endl;


return 0;
}

dal4488
Newbie Poster
17 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

You need to terminate the following statements with semicolons:

const double conversion = 2.54;
const int inchesPerFoot = 12;


And this was okay many years ago...

#include <iostream.h>


...but if you are living in the 21st century, it should be...

#include <iostream>


...especially since you are...

using namespace std;
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

Just a hint, after doing Dave's corrections study up on the modulus operator % ...

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You