-4

I'm trying to make a separate function that takes parameters x and y from the main function use use it in the powf, assign it to a variable 'result' and output it to the main function. Any help is appreciated

#include <stdio.h>
#include <math.h>

int  main() {

  float x = 5.5;
  float y = 3;
  float total = 1;
  int i;


  for( i=0; i <= y; i++ ) {
    total = total * x;
  }

  printf("total = %.3f\n",total);
  printf("Result of powf function is: %.3f\n", result);

  return 0;

}

float mathPow(float x, float y){

  result = powf(x,y);

  return result;

}
Adi
  • 9
  • 7

2 Answers2

0

I have modified your code a bit

float mathPow(float x, float y){
  float result = powf(x,y);
  return result;
}
int  main() {

  float x = 5.5;
  float y = 3;
  float total = 1;
  int i;
  for( i=0; i <= y; i++ ) {
    total = total * x;
  }
  printf("total = %.3f\n",total);
  printf("Result of powf function is: %.3f\n", mathPow(x,y));
  return 0;
}

as you can see you did not called the function mathPow() in your main().

In order to execute the User Define functions you need to call them from your main()

Digvijaysinh Gohil
  • 1,367
  • 2
  • 15
  • 30
0

This is the whole program working

#include <stdio.h>
#include <math.h>


float mathPow(float x, float y);

int  main() {

  float x = 5.5;
  float y = 3;
  float total = 1;
  int i;


  for( i=0; i < y; i++ ) {
    total = total * x;
  }

  printf("total = %.3f\n",total);
  printf("Result of powf function is: %.3f\n", mathPow(x,y));

  return 0;

}

float mathPow(float x, float y){

 float result = powf(x,y);

  return result;

}
Adi
  • 9
  • 7