Getting errors while it seems it's all correct?

Write your question 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stdafx.h"
#include "iostream"
#include <math.h>
using namespace std;


int main()
{
	BEGIN: int solid;
	cout << "Insert a number of the geometric solid you want to calculate the following: V, O, d, D and/or v: " << endl;
	cout << "1. CUBE" << endl;
	cout << "2. CUBOID" << endl;
	cout << "3. PYRAMID" << endl;
	cout << "4. SPHERE" << endl;
	cin >> solid;
	switch (solid)
	{
	case 1:
		float a, V, O, d, D;
		cout << "Insert side a in cm: " << endl;
		cin >> a;
		V = pow(a, 3);
		O = 6 * pow(a, 2);
		d = sqrt(2);
		D = sqrt(3);
		cout << "Volume= " << V << endl;
		cout << "Surface area= " << O << endl;
		cout << "Flat diagonal= " << d << endl;
		cout << "Spatial diagonal: " << D << endl;
		break;
	case 2:
		float a, b, c, V, O, d, D;
		cout << "Insert side a, b and c in cm: " << endl;
		cin >> a >> b >> c;
		V = a*b*c;
		O = 2 * (a*b + b*c + a*c);
		d = sqrt(pow(a, 2) + pow(b, 2) + pow(c, 2));
		D = sqrt(pow(a, 2) + pow(b, 2));
		cout << "Volume= " << V << endl;
		cout << "Surface area= " << O << endl;
		cout << "Flat diagonal= " << d << endl;
		cout << "Spatial diagonal: " << D << endl;
		break;
	case 3:
		float a, b, B, v, V, P, O;
		cout << "Insert side a and b in cm: " << endl;
		cin >> a >> b;
		B = pow(a, 2);
		V = 1 / 3 * B;
		v = a*sqrt(3) / 2;
		P = 4 * 1 / 2 * a*v;
		O = B + P;
		cout << "Volume= " << V << endl;
		cout << "Surface area= " << O << endl;
		cout << "Elevation= " << d << endl;
	case 4:
		float V, O, r, pi;
		cout << "Insert the sphere radius: " << endl;
		cin >> r;
		pi = 3.14159265359;
		V = 4 / 3 * pow(r, 3)*pi;
		O = 4 * pow(r, 2)*pi;
		cout << "Volume= " << V << endl;
		cout << "Surface area= " << O << endl;
		break;
	default:
		goto BEGIN;
	}
	system("pause");
	return 0;
}


So, the problem is that I really don't know what I did wrong but I still get build errors:

1>------ Build started: Project: tijela, Configuration: Debug Win32 ------
1> tijela.cpp
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(27): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(28): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35): error C2086: 'float a' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'a'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35): error C2086: 'float V' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'V'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35): error C2086: 'float O' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'O'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35): error C2086: 'float d' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'd'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35): error C2086: 'float D' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'D'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(48): error C2086: 'float a' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'a'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(48): error C2086: 'float b' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(35) : see declaration of 'b'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(48): error C2086: 'float V' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'V'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(48): error C2086: 'float O' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'O'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(53): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(60): error C2086: 'float V' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'V'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(60): error C2086: 'float O' : redefinition
1> c:\users\stipan\desktop\tijela\tijela\tijela.cpp(22) : see declaration of 'O'
1>c:\users\stipan\desktop\tijela\tijela\tijela.cpp(63): warning C4305: '=' : truncation from 'double' to 'float'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I'd appreciate any help cause this is for school!
Thank you!
Clue about the errors (the first two are warnings):
1
2
3
4
float a, V, O, d, D;
float a, b, c, V, O, d, D;
float a, b, B, v, V, P, O;
float V, O, r, pi;


also, do not use goto. Use a loop instead.
Last edited on
If mutexe's reply wasn't clear, switch cases do not create new scopes. You're trying to define the same variables in the same scope (main's local variables).
Oh, I understand now, thank you!
Topic archived. No new replies allowed.