You are here:

C/Minutes and seconds as arguments

Advertisement


Question
Joesph Moore,

Hi I had a question about this program i am trying to write for my programming class. The program I am trying to write is:

Write a program that asks the user for the race time in minutes and seconds for a runner. Then compute and display the speed in feet per second and in meters per second. Write and call a function that displays instructions to the user. Also write a function that takes minutes and seconds as arguments and prints the results.

The instructions part is easy that is simply a printf statement. I dont understand what he means by taking minutes and seconds as arguments though.

#include <stdio.h>
#define meter 3282
#define foot 5280

int
main (void)
{
       double  minutes,
               seconds,
       printf("$ track\n");
       printf("This program will ask for the minutes and seconds for the time it took for a runner to run a mile. The program will then calculate the feet per second and meters per second for that runner.\n");
       printf("Minutes for the runner: ");
       scanf("%lf",&minutes);
       printf("Seconds for the runner: ");
       scanf("%lf",&seconds);

       totalseconds=seconds+(minutes/60)


       return(0);
}

This is what I have so far...

Answer
You are being asked to write a function which you call that does the work.  Just like your main function here is a function which takes no arguments, you must write a function which takes some arguments (or parameters) such as:

   void foo(int bar);

The above function template takes an integer as a parameter.  Your program would call a function to ask for and store the data, then call a function with the input and print the results.  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joseph Moore

Expertise

I've been programming in one form or another since my brother taught me BASIC when I was 6. I've been programing professionally since I was 20, first web development with HTML, JS, DHTML, CSS, etc., then I became a video game developer, writing code in C, C++, C#, SQL, assembly, and various scripting languages. I've even written my own scripting languages, custom designed for the games I was making. I also dabble in Java, PHP, and Perl. I've worked on pretty much every aspect of game development, including graphics, audio, gameplay, tool, UI, input, animation, and physics.

Experience

I've been writing C code for 12 years, both on my own in my spare time and professionally.

Organizations
IGDA

Education/Credentials
Bachelor of Science in Game Design and Development, Full Sail University, Winter Park, FL

Awards and Honors
Salutatorian and Advanced Achiever Awards at Full Sail; Independent Games Festival Student Showcase winner, 2004; Featured article on Gamasutra about an experimental game developed in 2004

©2012 About.com, a part of The New York Times Company. All rights reserved.