Shapes/Calculation program

Ok... I might be missing something or whatever in the program. The assignment is to allow user to enter in a shape and its dimensions in a file. Also, to calculate the area, perimeter, volume, and/or surface area of all the shapes in the file that the user has entered. I tried to compile the program and its not showing up anything? I might be missing something and its not complete with the calculation for the shapes. I just want the basic thing to show up then do the calculation later. I'm using the gcc/g++ compiler and they're accurate version which works with my other cpp programs.

Here is the program:
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	//declare variables to use for storing user's input
	
	int choiceOne;
	char choiceTwo;
	char filename[21];
	char userRunProgram[1];
	
	double height, width;
	double area, perimeter, volume;
	double radius, radiusA, radiusB;
	double sideA, sideB;
	double sideC, sideD;
	
	const double PI = 3.1415926;
	bool goagain = true;
	char response;
	
	// function prototypes

	double calcCylinderVolume(double, double);

	cout << fixed << showpoint << setprecision(2);
	
	// User chosing the menu options

	cout << "Welcome to the SHAPE program." << endl << endl;
	
	while (goagain == true)
	{	
		cout << "\nPick from the following menu options." << endl;
		cout << "\t 1. Add a shape to a file." << endl;
		cout << "\t 2. Calculate area, perimeter, and volume of shapes in a file." << endl;
		cout << "\t Enter 1 or 2:";
		cin >> choiceOne;
	
		if (choiceOne == 1)
		{
			cout << "You have chosen to add a shape to a file.";		
			cout << "Please enter the name of the file:";
			cin >> filename;
			ofstream shapes(filename, ios::out);
			cout << "What shape do you wish to enter?";
			cout << "a. Square\t";
			cout << "b. Rectangle\t";
			cout << "c. Parallelogram\t";
			cout << "d. Trapezoid\t";
			cout << "e. Circle\t";
			cout << "f. Ellipse\t";
			cout << "g. Triangle\t";
			cout << "h. Cube\t";
			cout << "i. Cylinder\t";
			cout << "j. Pyramid\t";
			cout << "k. Cone\t";
			cout << "l. Sphere";
			cout << "\t Choose a lowercase letter between a and m:";
			cin >> choiceTwo;
			
			switch (choiceTwo)
			{
				case 'a': cout << "You want to enter a square.\n";
						  break;
				case 'b': cout << "You want to enter a square.\n";
						  break;
				
				default:  cout << "You did not enter any letter from a to l.\n";
			}
		}
		else if (choiceOne == 2)
		{
			cout << "\nYou have chosen to calculate area, perimeter ";
			cout << "and/or volume of shapes from a file.";
		}
		else
			cout << "You did not enter a valid choice of 1 or 2.\n";
			cout << "\nDo you wish to run the program again? (y/n)\n";
			cin >> response;
			if (response == 'n' || response == 'N')
				goagain = false;
				
	} //end of while loop
	
	cout << endl;
	
	return 0;

}//end of main function 
You seem to have coded all the prompts, but you don't actually perform any calculations.
I know.. I stated that I didn't put in any calculations yet. Anyways, I got it fixed to show up. Have an issue right now which its in the filestreaming to append data. It's only able to record first part of the shape but it refused to record the second shape?

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
137
138
139
140
141
142
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	//declare variables to use for storing user's input
	
	int choiceOne;
	char choiceTwo;
	char filename[21];
	
	double height, width;
	double area, perimeter, volume;
	double radius, radiusA, radiusB;
	double sideA, sideB;
	double sideC, sideD;
	
	const double PI = 3.1415926;
	bool goagain = true;
	char response;

	ofstream inputFile;
	char line[21];
	
	// function prototypes

	double calcCylinderVolume(double, double);

	cout << fixed << showpoint << setprecision(2);
	
	// User chosing the menu options

	cout << "\nWelcome to the SHAPE program." << endl << endl;
	
	while (goagain == true)
	{	
		cout << "\nPick from the following menu options." << endl;
		cout << "\t 1. Add a shape to a file." << endl;
		cout << "\t 2. Calculate area, perimeter, and volume of shapes in a file." << endl;
		cout << "\t Enter 1 or 2: ";
		cin >> choiceOne;
	
		if (choiceOne == 1)
		{
			cout << "\nYou have chosen to add a shape to a file." << endl;		
			cout << "\n\nPlease enter the name of the file: ";
			cin >> filename;
			ofstream shapes(filename, ios::out);
			cout << "\nWhat shape do you wish to enter?" << endl;
			cout << "\t a. Square" << endl;
			cout << "\t b. Rectangle" << endl;
			cout << "\t c. Parallelogram" << endl;
			cout << "\t d. Trapezoid" << endl;
			cout << "\t e. Circle" << endl;
			cout << "\t f. Ellipse" << endl;
			cout << "\t g. Triangle" << endl;
			cout << "\t h. Cube" << endl;
			cout << "\t i. Cylinder" << endl;
			cout << "\t j. Pyramid" << endl;
			cout << "\t k. Cone" << endl;
			cout << "\t l. Sphere" << endl;
			cout << "\t Choose a lowercase letter between a and m: ";
			cin >> choiceTwo;
			
			switch (choiceTwo)
			{
			
				case 'a': 
						  cout << "\n\nYou want to enter a square." << endl;
						  cout << "Enter the height of the square: ";
						  cin >> height;
						  inputFile.open(filename, ios::out);
								if (! inputFile)
								cout << "Error opening file.";
		    			  inputFile << "SQUARE:\r\n";
						  inputFile << height;
						  inputFile.close();

						  cout << "\nYou have entered a shape in " << filename << ". \n";
						  break;
				case 'b': cout << "\n\nYou want to enter a rectangle.\n";
						  cout << "Enter the width of the rectangle: ";
						  cin >> width;
						  cout << "Enter the height of the rectangle: ";
						  cin >> height;
						  inputFile.open(filename, ios::out | ios::app);
								if (! inputFile)
								cout << "Error opening file.";
		    			  inputFile << "RECTANGLE:\r\n";
						  inputFile << width << "\r\n";
						  inputFile << height;
						  inputFile.close();

						  cout << "\nYou have entered a shape in " << filename << ". \n";
						  break;
				case 'c': cout << "You want to enter a parallelogram.\n";
						  break;
				case 'd': cout << "You want to enter a trapezoid.\n";
						  break;
				case 'e': cout << "You want to enter a circle.\n";
						  break;
				case 'f': cout << "You want to enter a ellipse.\n";
						  break;
				case 'g': cout << "You want to enter a triangle.\n";
						  break;
				case 'h': cout << "You want to enter a cube.\n";
						  break;
				case 'i': cout << "You want to enter a cylinder.\n";
						  break;
				case 'j': cout << "You want to enter a pyramid.\n";
						  break;
				case 'k': cout << "You want to enter a cone.\n";
						  break;
				case 'l': cout << "You want to enter a sphere.\n";
						  break;						  
						  
				default:  cout << "You did not enter any letter from a to l.\n";
			}
		}
		else if (choiceOne == 2)
		{
			cout << "\nYou have chosen to calculate area, perimeter ";
			cout << "and/or volume of shapes from a file.";
		}
		else
			cout << "You did not enter a valid choice of 1 or 2.\n";
			cout << "\nDo you wish to run the program again? <y/n>: ";
			cin >> response;
			if (response == 'n' || response == 'N')
				goagain = false;
				
	} //end of while loop
	
	cout << endl;
	
	return 0;

}//end of main function 
You have it set up so that the person inputting data from the keyboard creates a new file and then the shape is stored in that file. Do you need to create a new file each time the program is run based on what the "user" (person typing) designates or could you just create one file that all the shapes are put in to?
Last edited on
It should be just one file for user to create to put all shapes into.
"I tried to compile the program and its not showing up anything?"

Does this mean the compiler is not showing anything or that when the program is run it doesn't output anything?
Nevermind about that. It was compiler issue that I've installed wrong. Although, other post about appending data is which I've got it fixed. So, thanks all for trying to help! ;)
Topic archived. No new replies allowed.