Okay. Well. Pseudo-endless loops are fine if they're short. But in the above case these loops are huge and you'll have to go hunting for any continues and breaks first to understand it.
First: you have a semicolon at the end of the following line, which reads as: if the condition is true, do nothing.
if (shape == 1 || shape == 2 || shape == 3 || shape == 4 || shape == 5 || shape == 6 || shape == 7);
Second, you can write that as:
if (shape>=1 && shape<=7)
Third, it's almost always better to avoid unnecessary nested blocks:
1 2
|
if (shape<1 || shape>7)continue;
//no block necessary for the case that a valid shape number was entered
|
Next up is breaking up this spaghetti code into several smaller functions: one just for 2D shapes and one for 3D shapes.
Both of these can call smaller functions that handle the selection and input and do the actual calculations.
As for why the screen "goes crazy"... this prints the line an infinite number of times:
1 2
|
for(;;)
cout<< "Do u want to get the area or the Perimeter:\n" << "1: Area\n" << "2: Perimeter\n\n" << "Corresponding number:\t";
|
You probably wanted to create a block here.
Also read the following if necessary:
http://www.cplusplus.com/doc/tutorial/control/