KUMA
KUMA

Reputation: 27

My final function will not return

In my code I have a function at the very end that will not return any results. I think it might be an issue with my pointers. I am not sure what to do, I am new to coding, so any help is appreciated.

#include <stdio.h>
#include <stdlib.h>
int PrintInstructions(void);
void GetData(float*, float*, float*);
double AccelerationDisplacement(float vi, float t, float a);
void PrintOutput (double result, float vi, float t, float a);
int main(void) 
{
  int x=PrintInstructions();
  float vi,t,a;
  double result;
  GetData(&vi,&t,&a);
  AccelerationDisplacement;
  PrintOutput;
  return 0;
}
int PrintInstructions(void)
{
  printf ("This program determines distance traveled based on the data given, if you wish to quit, enter 'q', if you wish to continue enter any other character:");
  char leave;
  leave= getchar();
  if (leave == 'q' || leave == 'Q')
    exit(0);
  else 
    return 1;
}
void GetData (float* vi , float* t, float* a)
{
  printf ("Enter the vehicle's initial velocity in m/s:");
  scanf ("%f",&vi);
  printf ("Enter the time the vehicle travels in seconds:");
  scanf ("%f",&t);
  printf ("Enter the rate of acceleration in m/s:");
  scanf ("%f",&a); 

}
 double AccelerationDisplacement (float vi, float t, float a)
 {
   float d=(vi * t)+ (.5 * a) * (t * t);
   double result;
   d=result;
   printf ("Your answer is:", result);
  }

Upvotes: 0

Views: 43

Answers (1)

user8969424
user8969424

Reputation:

Since I do not have enuf rep to comment directly under the question, I'm going to put it here. As Retired Ninja says,

  1. you do not need the extra & in your scanf as you are already passing pointers as arguments (I suggest you spend some time understanding what & in scanf signifies)

  2. AccelerationDisplacement and PrintOutput are functions. So, when you call them, you need to have () next to them and pass the relevant arguments in the same order as the declaration at the top -

    AccelerationDisplacement(vi, t, a);

    PrintOutput(vi, t, a);

As a piece of unsolicited advice, learn how to step through each line using tools like gdb for debugging. That will help a lot in understanding what the code is doing.

Upvotes: 2

Related Questions