Working with functions (void), where am i messing up?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 #include <iostream>
using namespace std;

void multiplicationFunction(); //multiplying input and num in the main function
{
	cout << num << " times " << input << " equals " << num * input << endl;
}

void additionFunction(); //adding input and num in the main function
{
	cout << num << " added to " << input << " equals " << num + input << endl;
}

int main() //using the while loop to run through both void functions 4 times for the integers 1-4
{
	int input = 0, num = 0;

	cout << "Please enter an integer: " << endl;
	cin >> input;
		while(int num = 1; num <= 4; num++)
		{
			multiplicationFunction();
			additionFunction();
		}
return 0;
}
Last edited on
You have quite a few errors.

you should read up on functions, i/o and loops.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

using namespace std;

void multiplicationFunction(int num, int input) //multiplying input and num in the main function
{
    cout << num << " times " << input << " equals " << num * input << endl;


}

void additionFunction(int num, int input) //adding input and num in the main function
{
    cout << num << " added to " << input << " equals " << num + input << endl;
}

int main() //using the while loop to run through both void functions 4 times for the integers 1-4
{
    int input = 0, num = 0;

    cout << "Please enter an integer: " << endl;
    cin >> input;

    while (num < 4) {


        multiplicationFunction(input, num);
        additionFunction(input, num);

        num++;

    }

    return 0;

}
Last edited on
i just got into functions so it's pretty fresh

and thanks i'll check into the pages about them.
Last edited on
Your addition/multiplication functions don't know what "num" and "input" are b/c they are scoped to inside main(). You need to pass them as parameters. like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void multiplicationFunction(int input, int num);
{
	cout << num << " times " << input << " equals " << num * input << endl;
}
//TO DO: See if you can figure out the addition function ;)

int main() //using the while loop to run through both void functions 4 times for the integers 1-4
{
	int input = 0, num;

	cout << "Please enter an integer: " << endl;
	cin >> input;
		while(int num = 1; num <= 4; num++)
		{
			multiplicationFunction(input, num);
			additionFunction();
		}
return 0;
}
Topic archived. No new replies allowed.