944,100 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3079
  • C++ RSS
Feb 11th, 2005
0

new to C++

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dal4488 is offline Offline
17 posts
since Feb 2005
Feb 11th, 2005
0

Re: new to C++

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
Team Colleague
Reputation Points: 36
Solved Threads: 2
PFO Founder
big_k105 is offline Offline
308 posts
since May 2003
Feb 11th, 2005
0

Re: new to C++

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

#include <iostream.h>

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;
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dal4488 is offline Offline
17 posts
since Feb 2005
Feb 12th, 2005
0

Re: new to C++

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...
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
...but if you are living in the 21st century, it should be...
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
...especially since you are...
C++ Syntax (Toggle Plain Text)
  1. using namespace std;
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Feb 12th, 2005
0

Re: new to C++

Just a hint, after doing Dave's corrections study up on the modulus operator % ...
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help finding and solving a problem
Next Thread in C++ Forum Timeline: How do assign a file name to save in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC