Thread: In Dire Need of Help (lots of it)

  1. #1
    Unregistered
    Guest

    Question In Dire Need of Help (lots of it)

    Hi,
    I am a very new programmer ( 1 month and counting). I am presented with a problem from a tutorial I recieved online and I have no idea how to even start with it. My only assumption is to use array's, but I am not sure how the function protypes are to work and what not. Also, its just plain complicated! (to me at least)
    I will write up what I need done, and if you can, give me tips on how and where to start, and what else I can do. It shouldn't be any more than one page of code. Inside the directions for it, I include the most I could come up with as far as psuedocode for it. (I just threw comments in there basically)

    Here is the problem:

    Calculate the time it takes a Marathoner to travel the distance traveled (provided below). *Of course you must assume that 8 hours is 1 day of travel*

    Have the user enter the following (cin):

    (7 individual Marathoners)
    Marathoners Name
    Running Speed
    Distance
    Elevation gain/loss

    The running speed cannot be less than 1 and not greater than 3 (mph). The running speed should be a floating point number (so that "1.5"s can be presented (ie, decimals (sig figures)))

    Somehow, create a function to calculate the marathoners's time traveled. The time (in hours) is: distance/running speed.

    Create a function to calculate for elevation gain/loss. For every 1000 feet of elevation gain/loss, add one hour to the running time. (elevation gain/loss, is going up and down a hill in essence)

    Output (cout) the result of each marathoner to the screen. The Marathoner's name and the time must be separated by a white space.
    Preferably the output should be as follows: "Name Time" (ie, Joe 2days, 4hours). Or at least thats how i see it. If you have an opinion on how to make it better let me know!

    Also, how does one go about create a data file?
    I would like to create a data file called "distance.txt". using the 'marathoner' problem; The file should contain the following on each line, separated by a white space:
    marathoners name, running Speed (MPH), distance to travel (miles), elevation gain/loss (feet).
    This one I REALLY have no idea how to start out!

    If I could recieve some help, that would be great!

    Please email me some of the coding, if you can, and don't feel like typing it up to post or whatever (^_^ )

    [email protected]

    Signed In desperate need of help ,

    THE FU FYTER

    Addendum: (Tell me if i'm getting anywhere)

    #include <iostream.h>
    //Function protype...is this correct?
    void runnername_array (int *, int);
    void main (void)
    {
    }

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    I'll tell ya 1 thing
    void main (void)
    should be
    Code:
    int main( void )
    lets see some more code or ideas, nobody here will write it all for you.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered
    Guest

    Question Help me some mo' pweeease!

    This is the most code that I've come up with (sorry i was away on vacation).
    _______________________________

    #include <iostream.h>
    //Function Protypes

    void main(void)
    {
    //Declare variables
    char hiker_name[12];
    float hiker_speed;
    float distance;
    float elevation;
    float travel_time;

    //loop so that operation repeats 7x...also the number the names
    for (int x =0; x<7; x++)
    {
    //have user input "name"-truncate at 12 characters
    cout<<"Enter Hikers Name(no more than 12 characters):"<<endl;
    cin>>hiker_name;

    //while the speed is between one and three...
    while(hiker_speed>=1 && hiker_speed<=3)
    {
    cout<<"Enter Hikers Speed (in mph):"<<endl;
    //...ask user to enter the hikers speed...
    cin>>hiker_speed;//...then allow hiker speed to be stored

    //if the speeed is not between 1 and three...then output 'invalid entry'
    if(hiker_speed < 1 || hiker_speed > 3)
    cout<<"invalid entry"<<endl;
    }



    //ask the user to input the number of miles traveled (distance)
    cout<<"Enter Number Miles Traveled:"<<endl;
    cin>>distance;//store to 'distance'

    //ask the user to input the elevation gain/loss (in feet)
    cout<<"Enter the Elevation Gained or Lost (in feet):"<<endl;
    cin>>elevation;//store to "elevation"
    }

    //perform operation that totals the time traveled using the given input
    travel_time=distance/hiker_speed;

    //if the elevation is more than one thousand...
    if (elevation>=1000)
    travel_time=travel_time+1;//...add 1 hour to the travel time

    //print out the screen the number (in sequence), the hiker's name, and his/her travel time
    cout<<x<<hiker_name<<travel_time<<endl;
    }
    _______________________

    Now my question is (it's changed a bit).
    How do I do a double dimensional array to store the seven names...its something like "rows x columns" or something but, i just don't know ::sob::

    Also, according to my problem, since one day is equal to 8hours, i need to total it so that It outputs days and hours

    ie, "2days, 4hours"

    The most I have come up with is to use integer numbers for travel time...someone reccomended using 'type coercioni' to hlep me...but i have no clue what that does(or IS) x_x.

    Now for the days and time thing...if i total it in hours then divide it by 8...it will come out with the number of days...now to get the number of left over hours, if I use modulus (%) to divide it with, that would come out with the left over hours correct?

    Help would be GREATLY appreciated...thanks a lot (again)

    C.Runfrom/axe/murder.cpp

  4. #4
    endo
    Guest
    Didn't I answer this on the cplusplus forums?

  5. #5
    Unregistered
    Guest
    i didn't get it...and their message board confuses me...

  6. #6
    Unregistered
    Guest
    yeah, its not the best forum. Anyway, here is some code to get you on your way. It generates the time taken and the additional time due to elevation.

    Code:
    	float distance = 3001;
    	float speed = 3;
    	float elevation = -1456;
    	float time = 0;
    	time = distance/speed;
    
    	int additonalTime = (int)elevation/1000;
    	cout << additonalTime;

  7. #7
    Unregistered
    Guest
    Thanks a lot! (a whole hell of a lot)

    the kung fu fyter...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to store lots of values in a vector?
    By DARKGuy in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2007, 03:41 PM
  2. In DIRE need of a job
    By Mr.Sellars in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 09-02-2007, 06:52 PM
  3. Lots of bitmaps
    By twomers in forum Windows Programming
    Replies: 1
    Last Post: 05-28-2006, 07:02 AM
  4. Replies: 3
    Last Post: 03-21-2004, 06:02 PM
  5. Need lots of help with tile engine
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 06-12-2002, 01:54 AM