Trying to Save User output to a text file,

Writing a program that calculates shapes sizes and dimensions
but i need to figure out how and where to save the users output into text file.
I'm stuck. Im using so many functions because i am required to.
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
  #include "stdafx.h"
#include<iostream>
#include<fstream>
using namespace std;
void inputUserAnswer(int & answer);
void calculations(int& answer, double& sides, double& radius, double& volume, double& area, double& sizeDiameter, double& height, double& diameter, double& circumference, double& baseRadius);
void showAnswer(int&answer, double& sides, double& radius, double& volume, double& area, double& sizeDiameter, double& height, double& diameter, double& circumference, double& baseRadius);
int answer;
double sides, radius, volume, area, sizeDiameter, height, diameter, circumference, baseRadius;

int main()
{
	cout << "\t\t\t\tWelcome to my shape calculator\n";
	cout << "\t\t\tCode has been written by Jose Delgado\n\n";
	char again;

	do
	{
		//string arr[] = "Square", "Circle", "Triangle";
		//call the 3 fucntions in turn
		inputUserAnswer(answer);
		calculations(answer, sides, radius, volume, area, sizeDiameter, height, diameter, circumference, baseRadius);
		showAnswer(answer, sides, radius, volume, area, sizeDiameter, height, diameter, circumference, baseRadius);


		cout << endl << "Enter Y to run again, any other key to exit: ";
		cin >> again;
	} while (again == 'y' || again == 'Y');

	//system("pause");
	return 0;
}

void inputUserAnswer(int & answer)
{
	cout << "What shape will you want to calculate a square, a circle or a triangle?\n\n";
	cout << "Enter 1 for a square, 2 for a circle, 3 for a triangle: ";
	cin >> answer;
	
	switch (answer)
	{
	case 1:
		cout << "\n\nYou have requested to calculate a Square/Cube\n\n";
		break;

	case 2:
		cout << "\n\nYou have requested to calculate a Circle/Sphere\n\n";
		break;

	case 3:
		cout << "\n\nYou have requested to calculate a Triangle/Cone\n\n";
		break;
	default:
		cout << "\n\nPlease choose a number from 1 to 3.";


	}
}

void calculations(int & answer, double& sides, double& radius, double& volume, double& area, double& sizeDiameter, double& height, double& diameter, double& circumference, double& baseRadius)
{
	double pi = 3.14159;
	
	
	
	if (answer == 1)
	{
		cout << "Enter the dimensions for the sqaure/cube(in inches): ";
		cin >> sides;
		area = sides*sides;
		volume = sides*sides*sides;
		
	}
	else if (answer == 2)
	{
		cout << "Enter the radius of your circle: ";
		cin >> radius;
		area = pi*(radius*radius);

		diameter = 2 * radius;

		circumference = 2 * pi*radius;
		volume = 4 / 3 * pi*(radius*radius*radius);
		
	}
	else if (answer == 3)
	{
		cout << "Enter the base size or diameter of the triangle: ";
		cin >> sizeDiameter;
		cout << "Enter the height of the triangle: ";
		cin >> height;

		area = height*sizeDiameter / 2;
		baseRadius = sizeDiameter / 2;
		volume = pi*(baseRadius*baseRadius)*height / 3;

		

		
		//cout << baseRadius<<sizeDiameter<<height<<area<<volume;
	}
	



}

void showAnswer(int & answer, double& sides, double& radius, double& volume, double& area, double& sizeDiameter, double& height, double& diameter, double& circumference, double& baseRadius)
{
	ofstream text("CTIM371_Project.txt");
	
		if (answer == 1)
		{
			cout << "\n\t\t\t\tSide Dimension: " << sides << endl
				<< "\t\t\t\tSide Area: " << area << endl
				<< "\t\t\t\tCube Volume: " << volume << endl;
		}
		else if (answer == 2)
		{
			cout << "\n\t\t\t\tRadius: " << radius << endl
				<< "\t\t\t\tDiameter: " << diameter << endl
				<< "\t\t\t\tCircumference: " << circumference << endl
				<< "\t\t\t\tCircle Area: " << area << endl
				<< "\t\t\t\tSphere Volume: " << volume << endl;
		}
		else if (answer == 3)
		{
			cout << "\n\t\t\t\tTriangle/Cone Base Radius: " << baseRadius << endl
				<< "\t\t\t\tTriangle/Cone Base Diameter: " << sizeDiameter << endl
				<< "\t\t\t\tTriangle/Cone Height: " << height << endl
				<< "\t\t\t\tArea: " << area << endl
				<< "\t\t\t\tCone Volume: " << volume << endl;
		}
	
}
You could save the output after the calculations.
Also your function calculations looks too complicated with so many parameters.
A better way would be to have functions like calcSquare, calcTriangle and so on if you are allowed.
It would be easier to advice you if you post the complete assignment.

Topic archived. No new replies allowed.