C programming functions

Someone_having_Interest

I'm very new to programming and recently I came across the function topic. As I wanted to experiment out my knowledge I wrote this very basic code

My aim is to make the separate read function, calculate function and print function and to call the three function in the main... However, this code doesn't show any error but the output that it gives is just the garbage value, how can I make it to really work?

#include <stdio.h>
#include <stdlib.h>
void read(int hrs,int pR);
int calc(int hrs, int pR);
void print(int res);

int main()
{
    int hours, payRate;
    read(hours,payRate);
    calc(hours, payRate);
    int c = calc;
    print(c);
}

void read(int hrs,int pR)
{
    printf("enter hours and pay rate");
    scanf("%d%d", &hrs, &pR);
}

int calc(int hrs, int pR)
{
    int grossPay = hrs * pR;

    return grossPay;
}

void print(int res)
{
    printf("The grossPay is %d", res );
}
JBR

try to pass value by reference

#include <stdio.h>
#include <stdlib.h>
void read(int *hrs,int *pR);
int calc(int hrs, int pR);
void print(int res);

int main()
{
int hours, payRate;
read(&hours,&payRate);
int c = calc(hours, payRate);
print(c);
}

void read(int *hrs,int *pR)
{
 printf("enter hours and pay rate");
 scanf("%d%d", &*hrs, &*pR);
}

int calc(int hrs, int pR)
{
 int grossPay = hrs * pR;

 return grossPay;
 }

void print(int res)
{
   printf("The grossPay is %d", res );
 }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C programming Arrays with Functions

From Dev

How to write multi-dimensional arrays in functions? C programming for beginners

From Dev

C Programming Math Functions #include <stdlib.h> abs()

From Dev

How to write multi-dimensional arrays in functions? C programming for beginners

From Dev

C++ template meta programming using template functions

From Dev

Programming recursive functions in alloy

From Dev

python programming with multiple functions

From Dev

Modular programming and functions prototypes

From Dev

Programming CRUD functions in PHP

From Dev

Virtual Functions and Generic Programming

From Dev

Meta Programming Functions And Tests

From Dev

Implementing functions in an interpreted programming language

From Dev

Order of execution of functions in functional programming

From Dev

Protocol Oriented Programming Optional Functions

From Dev

Cuda Programming in comparision with C Programming

From Dev

Cuda Programming in comparision with C Programming

From Dev

Are all pure functions in functional programming continuous?

From Dev

Invoking nested functions in the Dart programming language

From Dev

Pointers, functions and arrays in D Programming Language

From Dev

D(2) Programming: chaining functions call on struct

From Dev

Pointers, functions and arrays in D Programming Language

From Dev

Mutually recursive functions in functional programming languages

From Dev

Need help using objects and functions -- new to programming

From Dev

Map two functions together in Functional Programming paradigm

From Dev

What is this C programming reading?

From Java

C programming in Visual Studio

From Dev

C programming Syntax

From Dev

Programming a reversed pyramid in c

From Dev

Graphics in C programming

Related Related

  1. 1

    C programming Arrays with Functions

  2. 2

    How to write multi-dimensional arrays in functions? C programming for beginners

  3. 3

    C Programming Math Functions #include <stdlib.h> abs()

  4. 4

    How to write multi-dimensional arrays in functions? C programming for beginners

  5. 5

    C++ template meta programming using template functions

  6. 6

    Programming recursive functions in alloy

  7. 7

    python programming with multiple functions

  8. 8

    Modular programming and functions prototypes

  9. 9

    Programming CRUD functions in PHP

  10. 10

    Virtual Functions and Generic Programming

  11. 11

    Meta Programming Functions And Tests

  12. 12

    Implementing functions in an interpreted programming language

  13. 13

    Order of execution of functions in functional programming

  14. 14

    Protocol Oriented Programming Optional Functions

  15. 15

    Cuda Programming in comparision with C Programming

  16. 16

    Cuda Programming in comparision with C Programming

  17. 17

    Are all pure functions in functional programming continuous?

  18. 18

    Invoking nested functions in the Dart programming language

  19. 19

    Pointers, functions and arrays in D Programming Language

  20. 20

    D(2) Programming: chaining functions call on struct

  21. 21

    Pointers, functions and arrays in D Programming Language

  22. 22

    Mutually recursive functions in functional programming languages

  23. 23

    Need help using objects and functions -- new to programming

  24. 24

    Map two functions together in Functional Programming paradigm

  25. 25

    What is this C programming reading?

  26. 26

    C programming in Visual Studio

  27. 27

    C programming Syntax

  28. 28

    Programming a reversed pyramid in c

  29. 29

    Graphics in C programming

HotTag

Archive