Quantcast

Maximum PC

It is currently Wed Oct 01, 2014 9:27 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: C++ Problem Help!!
PostPosted: Tue Sep 21, 2004 5:32 pm 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
I've never asked anybody for a favor here in the forums but I have this C++ problem due tomorrow and I haven't had time to read the first chapter of our book so I have no idea how to do it....arghhhhhh.....first 2 weeks of college have been hectic...so much work...could anybody help me with this problem....THANK YOU ANYBODY WHO HELPS!!!!

I don't think the problem should be to difficult since its the first one for the beginners C++ class I'm taking.





DUE DATE: Wednesday September 22 at the start of lecture.

Calorie Calculator

Write a calculator that will determine how many calories you burn when you run a given distance. You only need to know your weight and the distance you have run. (Note: You can enter decimals for the distance. For example—3.5 miles).

Distance should be entered as miles. Weight should be entered as pounds. The calculator will convert miles and pounds to kilometers and kilograms for the calculation.

Formulas you will need to write this program:

calories burned = kilometers x kilograms x 1.036
1 mile = 1.609 kilometers
1 pound = 0.4536 kilograms

Requirements:

-Your program must be well commented. A comment that describes each variable as it is declared must be present.
-Comments must also describe any formulas in your code.
-Output should be aligned and spaced in a clear, readable format.
-Output must be accurate.
- When you run the program, it must output this information to the user before asking the user for the distance and weight:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If you're running to lose weight, remember that the calories you burn each day (through running and other activities) must exceed the calories that you consume each day in food and drinks. The more regularly you run, and the more carefully you watch your diet, the more weight you'll lose.

Because running forces you to move the entire weight of your body (unlike, say, rowing and bicycling, where you sit on your butt), it's a very high calorie-burning exercise. Tens of thousands of people have used to running to lose weight, and keep it off.

You don't have to run fast to burn calories. It's more a matter of how far you run, not how fast. Your weight does matter, however, since it takes more energy to move a heavy object than a light one.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What to turn in:
1 - A print out of your program.
2 - A print out of your programs output using this data for input:
distance = 12 miles
weight = 183 pounds
3 - A printed copy of an algorithm ( in the format of a numbered list of sequenced steps).


Top
  Profile  
 
 Post subject:
PostPosted: Tue Sep 21, 2004 5:45 pm 
Clawhammer
Clawhammer
User avatar

Joined: Sat Jun 26, 2004 2:16 pm
Posts: 3600
Just look at one of the example programs.

You will need header files
#include <iostream>

int main()
{

double kilogram...and the rest
declare kilogram as the value for a pound how you will need for an equation


cout<< "Enter such and such"<<endl;
cin>>miles;
and so on
then calculate and output.


}


Top
  Profile  
 
 Post subject: Re: C++ Problem Help!!
PostPosted: Tue Sep 21, 2004 6:43 pm 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Wed Jun 16, 2004 5:29 pm
Posts: 6328
Location: Far away from you
Gigahertz17 wrote:
I have this C++ problem due tomorrow and I haven't had time to read the first chapter of our book


Better get cracking then...

Unless of coarse you need help with time management and reading comprehension.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 8:03 am 
Smithfield
Smithfield
User avatar

Joined: Thu Jul 22, 2004 2:17 pm
Posts: 5315
Location: northwest BC
PROGRAMMERS PARADISE

But really, shouldn't you learn to do your coding assignments on your own?

I know, I know, there is just so much to do! There's all the pretty girls to gawk at (or handsome boys to flirt with) there's all that freedom of living in dorm, the nightly party, the daily hangovers, the coffee klatch bull sessions, it is just soooooooo hard to squeeze in time to study.

Hey, been there, done that, chewed the bone. Not flaming you, but you do have to learn to set priorities. :?


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:12 am 
Bitchin' Fast 3D Z8000
Bitchin' Fast 3D Z8000
User avatar

Joined: Fri Jul 23, 2004 3:44 pm
Posts: 216
Hmm, so you come here and ask everyone to help you cheat? Sorry, but I don't think so. Now if you write it and it doesn't work properly, feel free to post your code and we might be able find the bugs and assist you that way. You're right though, it is a fairly simple program, get cracking and lay off the beer ;)


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 2:38 pm 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
Okay I couldn't get it to compile so I didn't turn it in today..drop in grade but oh well. Tell me if this is correct...the damn thing won't compile..I'm using "Microsoft Visual Studio .NET 2003."

I don't think I'm creating the right kind of project. I go to "Make New Project" then go to the "Project" pull down meny and choose "Add New Item" and choose C++ File where it opens a blank page to type code into. It won't compile my code below though. WTF is wrong?

I'm going to the "Debug" drop down menu then "Start Without Debugging." Is that correct?



#include <iostream>
using namespace std;
int main (void)

{
double distance_miles, calories_burned, weight_pounds;

cout << "Enter the distance you ran in miles\n";
cout << "and your weight in pounds.\n";
cout << "Then press return.\n";
cin >> distance_miles;
cin >> weight_pounds;

calories_burned = (weight_pounds * 0.4536)(distance_miles * 1.609) * 1.036

cout << distance_miles << " miles\n";
cout << weight_pounds << "pounds\n";
cout << "Total calories burned is" << calories_burned;

return 0;
}


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 5:02 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
IMO, one of the biggest favors a person can do for themselves when just learning C++ is not to use something like VS. You have enough to learn w/o having to worry about a bunch of IDE nonsense that won't help you.

Also, if you learn how to debug your own programs, pretty soon the right wires in your brain will connect and you will be less dependent on a debugger. There really is no substitute for looking at and understanding code, sitting down and solving problems, etc. It takes a bit more time upfront, but pays huge dividends in the long run, and lets face it, in this environment, a second-rate programmer is going to have a very tough time finding work.

The programmers resource list has some free C++ compiler suggestions. I would recommend Textpad and Borland initially and then you might want to try Eclipse when you have a weekend to go over a few tutorials. Good luck.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 5:05 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Gigahertz17 wrote:
calories_burned = (weight_pounds * 0.4536)(distance_miles * 1.609) * 1.036


Since I'm feeling bad for you. Take a look at this line. What are you trying to do - mathematically.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 5:15 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
If you want a lot of help with your programming, check out a C++ forum, like http://www.cpp-home.com/forum/ .

Code:
#include <iostream>
using namespace std;
int main (void)//perfectly fine
{
double distance_miles, calories_burned, weight_pounds;

cout << "Enter the distance you ran in miles\n";
cout << "and your weight in pounds.\n";
cout << "Then press return.\n";
cin >> distance_miles;
cin >> weight_pounds;

calories_burned = (weight_pounds * 0.4536)*(distance_miles * 1.609) * 1.036;
//you needed a * sign and an semicolon

cout << distance_miles << " miles\n";
cout << weight_pounds << " pounds\n";
cout << "Total calories burned is " << calories_burned;


cin.ignore(1);//ignore the newline
cin.get();//optional, but it lets you see the output
return 0;
}


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 8:48 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
We don't appreciate people spamming other forums here, especially when we have more than enough qualified people who can help him here. We've always had a policy of NOT doing students homework - for good reason.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 9:05 pm 
Team Member Top 100
Team Member Top 100

Joined: Fri Sep 17, 2004 5:35 pm
Posts: 1176
And I agree with it.
However, since it was a simple fix, I believe showing the code in its entirety is just as helpful, as they see how it all fits together.
I was just saying that if they really wanted some help with C or C++, they should join a C or C++ forum -- simply because there is a higher probability of more and more advanced C and C++ programmers there.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Sep 22, 2004 11:06 pm 
Bitchin' Fast 3D Z8000*
Bitchin' Fast 3D Z8000*
User avatar

Joined: Tue Jun 29, 2004 11:32 pm
Posts: 2555
Location: Somewhere between compilation and linking
Kybo_Ren wrote:
And I agree with it.
However, since it was a simple fix, I believe showing the code in its entirety is just as helpful, as they see how it all fits together.
I was just saying that if they really wanted some help with C or C++, they should join a C or C++ forum -- simply because there is a higher probability of more and more advanced C and C++ programmers there.


Yeah, but if we take that logic to the extreme, it implies that we should shut down this folder (in fact, the entire forum w/ the exception of one folder/topic)! It doesn't hurt, and I am sure that many people use other forums, but I don't think we should be in the practice of sending people elsewhere, when as I stated previously, we have plenty of C/C++ programmers willing to help here.

When someone asks a question that cannot be answered by someone here, then we should say.... yeah, I hear the forums over at _____ are pretty good. ;)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 5:53 am 
Thunderbird
Thunderbird
User avatar

Joined: Wed Jul 07, 2004 1:13 pm
Posts: 817
Location: Missouri
Gigahertz17 wrote:
Okay I couldn't get it to compile so I didn't turn it in today..drop in grade but oh well. Tell me if this is correct...the damn thing won't compile..I'm using "Microsoft Visual Studio .NET 2003."

I don't think I'm creating the right kind of project. I go to "Make New Project" then go to the "Project" pull down meny and choose "Add New Item" and choose C++ File where it opens a blank page to type code into. It won't compile my code below though. WTF is wrong?

I'm going to the "Debug" drop down menu then "Start Without Debugging." Is that correct?

Code:
#include <iostream>
using namespace std;
int main (void)

{
   double distance_miles, calories_burned, weight_pounds;

   cout << "Enter the distance you ran in miles\n";
   cout << "and your weight in pounds.\n";
   cout << "Then press return.\n";
   cin >> distance_miles;
   cin >> weight_pounds;

   calories_burned = (weight_pounds * 0.4536)(distance_miles * 1.609) * 1.036

   cout << distance_miles << " miles\n";
   cout << weight_pounds << "pounds\n";
   cout << "Total calories burned is" << calories_burned;

   return 0;
}


Do you get any errors? I think one problem would be with the following line missing the ; at the end of the line.

It should look like this if I am correct.:

Code:
calories_burned = (weight_pounds * 0.4536)(distance_miles * 1.609) * 1.036;


Is the
Code:
\n
forcing a carrage return? I was taught to use
Code:
<< endl
for each carrage return desired.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 5:57 am 
Coppermine
Coppermine
User avatar

Joined: Sat Jul 03, 2004 10:56 am
Posts: 709
Yeah I finally found out that line wasn't a proper function. I didn't know since visual studio wasn't giving me any sort of error messages dealing with my code.

Apparently when you start a "New Project" using Visual Studio you have to "Add New File" then go to a .cpp file. After I did that it finally worked.

I guess to see if your code works you first have to go to "Build Problem" then after it builds it you go to "Start without Debugging" then it will output it to a look a like MS-DOS window.

When you guys do C++ what menu options do you choose to test it then output it? I guess now all I have to do is compile since I know the code works. We'll see how that goes. Thanks all.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 10:53 am 
I judge you GUILTY!
I judge you GUILTY!
User avatar

Joined: Tue May 25, 2004 4:38 pm
Posts: 162
Location: New York City
Gigahertz:

For skipping a new line in C++ you can either write the following:
Code:
cout << "My cat: \n";


This simply just gives skips a line.

This code
Code:
cout << "My dog: " << endl;


will do the same thing except it will flush the buffer. Meaning that if stuff is still in memory, it will dump the whole thing. Not important at this stage of your programming 'career'.

----

To work with Visual Studio.net 2003, I open a New Project, I choose C++, then I select Console Application, then I go to options, deselect everything (so I only get a pure MS-DOS console application) and then I an add file to the Source folder.

Then I put the basics like
Code:
#include<iostream>
using namespace std;

int main()

{
}


Then I start coding.





[/code]


Top
  Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 12:04 pm 
Java Junkie
Java Junkie
User avatar

Joined: Mon Jun 14, 2004 10:23 am
Posts: 24224
Location: Granite Heaven
Gigahertz17 wrote:
When you guys do C++ what menu options do you choose to test it then output it? I guess now all I have to do is compile since I know the code works. We'll see how that goes. Thanks all.


Menu options? :?

CLI or nothing. :D


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.