void functions && POINTER

How do I write what the output of a void function into a file if I cannot assign it a variable? Here is my code.

This is the assignment.

Write a program in a cpp file called Pointer_LastNameFirstName.cpp that uses three functions. Two of the functions accepts addresses of variables as arguments. (Pointers should be use) The other function has no arguments.
First void function should be named getInputs, has two parameters called input_A and input_B (integer pointers parameter). This function asks the user for two numbers. The values entered are stored in the variables that are return to main.
Second void function named ProductofNumbers has two parameters called val_A and val_B (both integer pointers parameters). This function should find the product of the two number (multiply the two numbers).
Third function named Output that reads the information from the last text file "referenceOutput_LastNameFirstName.txt" and output it to the screen. (Simple as it sound! Don't over think this function)
All output should be written to the screen and to a text file called "PointerOutput_LastNameFirstName.txt" even the output from the old text file called "referenceOutput_LastNameFirstName.txt"

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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void getInputs(int *input_A, int *input_B);
void ProductofNumbers(int *val_A, int *val_B);
void Output();

int main() {
	ofstream newfile("PointerOutput_af.txt");
	if (newfile.is_open()) {


		int Num1, Num2;
		getInputs(&Num1, &Num2);
		ProductofNumbers(&Num1, &Num2);


		Output();
		
		newfile.close();
	}
	return 0;
}

void getInputs(int *input_A, int *input_B) {
	cout << "Please enter two numbers seperated by space: ";
	cin >> *input_A >> *input_B;

}

void ProductofNumbers(int *val_A, int *val_B) {
	int product;

	product = ((*val_A) * (*val_B));

}

void Output() {
	ifstream myfile("referenceOutput_asdf.txt");
	string str1;
	if (myfile.is_open()) {
		while (getline(myfile, str1)) {
			cout << str1 << endl;
		}
		myfile.close();
	}
	else cout << "Unable to open file";
}


I've tried using the following statement but I haven't had any luck yet.

1
2
newfile << output; 
newfile << output();


Also how am I supposed to get the value of my ProductofNumbers and print it out if I can assign it a value?

Last edited on
Topic archived. No new replies allowed.