file input/output

closed account (Diz60pDG)
I am working on an assignment in which the user enters a file name and the program will print out a table containing each number found, what that number is squared and a current sum of the values.

This is the code I have written so far, but am confused as to where I go from here.
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
  #include <iostream>
#include <fstream>
#include <string>
using namespace std;

double print_table(int value, int currentsum);

int main()
{
	ifstream input;
	string inf;

	cout << "Enter the name of the input file: ";
	cin >> inf;
	input.open(inf.c_str());

	if (input.fail())
	{
		cout << "File failed to open." << endl;
		return 0;
	}

	input.close();
	return 0;

}
	
	double print_table(int value, int currentsum)
	{
		
		for (int i = 0; i < value; i++)
		{
			currentsum = value + value;
		}
		
			
		
		cout << "x" << "\tx^2" << "\tCurrent Sum" << endl;
		cout << "=" << "\t===" << "\t===========" << endl;	
		cout << value << "\t" << value*value << "\t" << currentsum << endl;



		return 0;
	}

		
Last edited on
Well first things first, you are not even calling your function, double print_table.
Topic archived. No new replies allowed.