Click here to Skip to main content
15,662,426 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can someone please help me to answer the following questions with explanation?

How many functions are defined in this program, besides the main() functions?
Give the prototype of each function?
Give the arguments of each function?

#include <iostream> 
#include <string>
using namespace std;

int addition (int, int );
int subtraction (int , int ); 
void directions();
void printResult(int , int , int , string);

int main ()
    int x,y,r;   
    cout << "Please enter the first integer: ";    
    cin >> x;    
    cout << "Please enter the second integer: ";    
    cin >> y;  
    r = addition(x,y);  
    r = subtraction(x,y);  
    return 0;

int addition (int a, int b)
    int r;  
    return (r);

int subtraction (int a, int b)
    int r;  
    return (r);

void directions() 
    cout << "********************************************************" << endl << "Hello!" << endl
    << "This Program asks the user for two integers, then prints the sum and difference" << endl

    << "******************************************************" << endl << endl;

void printResult(int a, int b, int result, string operation)
    cout << a << " " << operation << " " << b << " = " << result << endl;
Updated 8-Nov-15 14:29pm
PIEBALDconsult 8-Nov-15 20:32pm    
What's a function?
Assam ALzookery 8-Nov-15 20:35pm    
A function is a block of code that has a name and it has a property that it is reusable it can be executed from as many different points in a C
PIEBALDconsult 8-Nov-15 20:41pm    
I thought that was a procedure.
PIEBALDconsult 9-Nov-15 8:31am    
Shhh... I'm trying to get the OP to think.

1 solution

Well this is probably your homework and you should do some thinking yourself.

The first step in analyzing any code is to make it easy to read.
I did that step for you.
How many functions do you see now?

As for prototypes and arguments that is kind of basic C knowledge.

You can read about prototypes here Wikipedia: Function prototype[^]
This page also cover the arguments.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900