SRL Archive - C/C++ Help and Tutorials

My C++ programs


Vinyl Scratch

2013-01-11 22:39:24

Hey, guys. I've started learning C++. (Just started tonight, actually)

Anyway, I've made a little program, and I though I might share it, get some CnC, and will add on to it, and post the updates here.

At the moment, when you run the executable, and you enter in the numbers, after you press enter twice, it closes. I'm looking into a fix for this. If you have one, lemme know, please!



Files:

Area finder. You type in the parameters, and it gives you the answer. It's a glorified multiplication calculator.


Source: http://paste.villavu.com/show/3806/
Source: http://pastebin.com/FHS32ujV

NKN

2013-01-11 23:14:24

Try not to do this:
cout << "\n" << endl;
cout << "\n" << endl;

You also don't need a endl on the end of every cout. Just put a \n at the end of your last one.

Gucci

2013-01-11 23:21:44

Nice I also just started learning c++ :D

Like yesterday and today were my first lectures, something I whipped up:

#include <iostream>
#include <windows.h>
using namespace std;

void Add()
{
double a, b, c;
cout << "Enter the first number" << endl;
cin >> a;
cout << "Enter the second number" << endl;
cin >> b;
c = a + b;
cout << a;
cout << " + ";
cout << b;
cout << " is equal to: ";
cout << c << endl;
Sleep(5000);
}

void Subtract()
{
double a, b, c;
cout << "Enter the first number" << endl;
cin >> a;
cout << "Enter the second number" << endl;
cin >> b;
c = a - b;
cout << a;
cout << " - ";
cout << b;
cout << " is equal to: ";
cout << c << endl;
Sleep(5000);
}

void Multiply()
{
double a, b, c;
cout << "Enter the first number" << endl;
cin >> a;
cout << "Enter the second number" << endl;
cin >> b;
c = a * b;
cout << a;
cout << " * ";
cout << b;
cout << " is equal to: ";
cout << c << endl;
Sleep(5000);
}

void Divide()
{
double a, b, c;
cout << "Enter the first number" << endl;
cin >> a;
cout << "Enter the second number" << endl;
cin >> b;
c = a / b;
cout << a;
cout << " / ";
cout << b;
cout << " is equal to: ";
cout << c << endl;
Sleep(5000);
}

int main()
{
int input;

cout << "What operation to perform (Add(1), Subtract(2), Multiply(3), Divide(4))" << endl;
cin >> input;
switch ( input ) {
case 1:
Add();
break;
case 2:
Subtract();
break;
case 3:
Multiply();
break;
case 4:
Divide();
break;
default:
cout << "Error, bad input, quitting\n";
break;

}

}

Edit: I see you Brandon, any pointers?

Brandon

2013-01-11 23:39:21

@OP and guy above, you're both missing error checking so if someone presses enter or doesn't enter anything, your program will get bad input and break.. If they enter letters, it will also break..

For now, pretty good for starters. Here's a tip. When I use strings and my std::cout statement ends in a string, I tend to use \n for new line.

If my statement doesn't end with a string, I use std::endl.

See below:


#include <iostream>

void Welcome()
{
std::cout<<"Welcome to Vinyl Scratch's AreaFinder!\n"; //Ends in quotes..
std::cout<<"It's my first C++ program, so I wanted to see if you guys liked it,\nand if I did well.\n\n\n"; //String..
}


int main()
{
Welcome();
unsigned long Width = -1, Height = -1;

std::cout<<"Enter Width: ";
std::cin>> Width;

if (!std::cin.good()) //If we get bad input.. Print an error and return 1.
{
std::cout<<"Error.. Invalid Input\n";
return 1;
}

std::cout<<"\nEnter Height: ";
std::cin>> Height;

if (!std::cin.good())
{
std::cout<<"Error.. Invalid Input\n";
return 1;
}

std::cout<<"The Area is: "<<Width * Height<<std::endl; //Doesn't end in a string.. Used std::endl.
std::cin.get();

return 0; //Everything went fine. Return 0..
}

Gucci

2013-01-11 23:44:07

^ could you explain the if loop? And what's std?

Vinyl Scratch

2013-01-11 23:49:39

Yeah, What Gucci said.

But I understand most of it. I didn't know what that /n did, so I just used endl.

Brandon

2013-01-11 23:54:40

std is a standard namespace.

If you don't do using namespace std; then you need to type std:: before everything within that namespace.

Ex:


using namespace std;

cout<<"Foo"<<endl;

string meh = "Testing";

Without the using, it'd be:


std::cout<<"Foo"<<std::endl;

std::string Meh = "Just Testing";

So on and so forth. A namespace basically stops confusion/ambiguity and groups stuff together.

Lets say you have two classes called "string". Lets say that the first string class resides in a namespace std and that the second one resides in namespace foo.


If you do something like:


using namespace std;
using namespace foo;

string Meh = "Testing std";
string Bleh = "Testing foo";

The above will give an error because the compiler will not know which string you are referring to. Why? Because you're using both namespaces and both of them have the same class.

Now if you did:


std::string Meh = "Testing std";
foo::string Bleh = "Testing foo";

The compiler now knows that the first line was referring to the string class within the namespace std group. The second line refers to the string class which is within the foo namespace/group.

That's all namespaces are used for. I tend to use the scope operator.. aka :: a lot because I once wrote my own library and had a lot of classes named the same thing as the ones already there.. Namespaces saved my ass so I use them lots lol. There usually is almost always no point to using them as much as I do, but it makes good practice I guess.

For beginning though, it's fine to ignore them. You usually tend to use them only if you think there is ambiguity or confusion.


Now for the cin.good(). Lets say you asked the user to enter a number.. But no, our user is a jerk and tries to break everything and crash our program. They decide to enter a letter or nothing at all. This sets a badbit flag in cin. Aka the Input stream. cin.good() lets you know if that flag is NOT set. I checked if the flag is set by doing:

If (Not good input) then show a message.

That's all.

Vinyl Scratch

2013-01-12 00:25:14

OHH. I understand, now! Thanks, Brandon. I'll start work on a new on tomorrow!

NKN

2013-01-12 00:37:41

Going to make an Algebra Calculator for the fun of it later.

Gucci

2013-01-12 00:45:44

If somebody enters a bad value aka letter/ not 0-4 then won't this:

default:         
cout << "Error, bad input, quitting\n";
break;

Output an error? Also how do you quote C++ code as C++ Code?

Brandon

2013-01-12 01:44:51

From: Gucci
If somebody enters a bad value aka letter/ not 0-4 then won't this:

default:         
cout << "Error, bad input, quitting\n";
break;

Output an error? Also how do you quote C++ code as C++ Code?


Your switch case is fine.. But imagine something like this:


#include <iostream>

int main()
{
int X = -1;

std::cout<<"Enter a number: ";
std::cin>> X;

switch(X)
{
case 0: std::cout<<"\n0 Entered"; break;
case 1: std::cout<<"\n1 Entered"; break;
case 'a': std::cout<<"\na Entered"; break;
default: std::cout<<"Default.."; break;
}

return 0;
}

Anything invalid that is entered will default to 0. Ex: If the user enters a, it will print: "0 Entered". So if your case statement counted 0, it'd be broken. Also note that it doesn't go to the 'a' case-statement ;) Since your code doesn't count 0, it is fine.

To do Cpp highlighting:

Highlight=C++
/Highlight

Put that in square brackets:

[.Highlight=C++]
[./Highlight]

Without the dots.

Gucci

2013-01-12 02:18:50

Ah I see what you mean, if I was counting 0 as a possible input for the case then if someone used anything not defined in the case it would execute this:

 case 0:
The procedure ();
Break;

Vinyl Scratch

2013-01-12 08:03:11

Oh, I see why it wouldn't work! I'll change it now.

Daniel

2013-01-12 08:26:28

If you haven't already, you might want to try my userscript for making the font in code-related tags monospaced (which I forgot to apply, when trying to read Brandon's examples :p). :)

EDIT: Vinyl Scratch, \n means to create a newline character. This is sometimes coupled with \r, especially when writing plain-text to files.

Vinyl Scratch

2013-01-12 13:50:04

Thanks, Daniel!


So, what does \r mean?

Brandon

2013-01-12 14:09:04

From: Vinyl Scratch
Thanks, Daniel!


So, what does \r mean?



\r means carriage return. This one tells the carret/cursor to go to the beginning of the line. Can be used to replace text.
\n means new line.

The difference? \r\n is new line on windows. \r is new line on macs. \n is new line on linux.

Well this is true afaik/learned. For compatibility reasons, when coding, I always use \r\n. If on macs, it will ignore the \n. On windows it uses both. On linux, it ignores the \r.

I think that's how it work or that's what I learned when I first started as well.

Also, for compatibility reason as well, Sockets require you to do \r\n so that no matter what system you're on, it registers new lines and separates the header from the body in HTML files as well as it signifies the end of a socket command during the request phase.


In a nutshell, it's best to just use \r\n but if you know that you're only going to be using windows/nix, using \n alone is pretty safe.


In Simba, a new line is \r\n which translates to #13#10 in bytes. You know this because those are the ascii values for them: http://www.asciitable.com/

Basically, \r goes down one line and to the beginning of the new line and \n just goes down one line with the caret in the same position. This happens only on some old systems though. I believe they both basically do the same thing now except it's platform specific.

Vinyl Scratch

2013-01-12 14:14:50

Thanks, Brandon. I'll just start using \r\n, to be on the safe side.

Working on my updated program right now!

SubiN

2013-01-14 03:19:51

are u programming c++ in windows if so how im pretty noob when it comes to visual i learnt in ubuntu and its really easy to compile using terminal and g++ commands

Gucci

2013-01-14 19:51:27

From: SubiN
are u programming c++ in windows if so how im pretty noob when it comes to visual i learnt in ubuntu and its really easy to compile using terminal and g++ commands


I've been using g++ or Dev C++, if you want a link to download g++ pm me

Vinyl Scratch

2013-01-14 20:09:36

I'll be sure to do that once I get my Linux Distro.


UPDATE! YAYY.

SubiN

2013-01-14 22:01:27

hmm this always bothered me does visual use an inbuilt g++ compiler or is it different if it is different what are the differences

Vinyl Scratch

2013-01-14 23:43:23

I couldn't tell you, I'm still new to C++. You'd have to ask Brandon that.

Daniel

2013-01-14 23:53:24

From: SubiN
hmm this always bothered me does visual use an inbuilt g++ compiler or is it different if it is different what are the differences


Why would Visual Studio use G++..?

And the GCC/G++ Windows counterpart is called MinGW.

Brandon

2013-01-15 00:21:26

From: Gucci
I've been using g++ or Dev C++, if you want a link to download g++ pm me


:o I thought the latest dev-C++ was since 07 or something.. 4.990/5.0 beta? Then.. I looked it up, turns out there is a new developer who started to continue it this year :l
Didn't even know this was happening till I saw your post.

I hope you meant this version of it: http://orwelldevcpp.blogspot.ca/


I personally use Codeblocks. Dev-C++ was back in the day and was my favourite IDE for a year or two. The best IDE that existed too. Now, my favourite is definitely without a doubt, Codeblocks.

http://www.codeblocks.org/downloads/26


I'm going to download that Dev-C++ and see how it is now. If it's as good as back then, I'm switching lol.

Visual Studio 2012 isn't bad either. It's actually pretty good. Though, it doesn't support half as many C++-x11 features as Mingw IDE's (Codeblocks/Dev-C++) or Clang/Intel..

VS2012's only advantage is the C++x11 Regex.. That's it. Other than that, your backend compiler should be g++/Mingw 4.7.2+.


Difference between VS2012 and Mingw? Well.. Two different compilers/backends. Mingw supports way more crossplatform stuff and more languages as well as the latest features whereas VS2012 is pure crap atm if it isn't Visual-C++ which is the .Net framework..


EDIT: I'm going to have to stick with codeblocks.. Dev-C++ just doesn't live up to its name for me anymore :c

Gucci

2013-01-15 00:46:09

Yeah that's the one

Vinyl Scratch

2013-01-15 08:07:02

OH! Sweet. I did something right when learning. I'm using CodeBlocks, too!

Kewl. Anyway, Brandon, Daniel, Could you take a look at my new code? I made some changes, and added perimeter.

Recursive

2013-01-16 19:57:52

You didn't put a catch for when the user enters a value that is not 0, 1, or 2. So if I put 3, it just exits…

Fix: a simple label is enough to fix this.

main()
start:
if (……………)
else if (……………)
else if (……………)
else
goto start;
end;

Vinyl Scratch

2013-01-16 23:43:56

I don't fully understand. Could you go into more detail?

Thanks for helping!

Recursive

2013-01-17 01:08:06

Labels are just overs simplified loops and are very useful if programming in very low level languages like any assembly language (MIPS). However that doesn't mean we can't make use of them in c++.

Like this:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

void Welcome()
{
cout << "\nWelcome to Vinyl Scratch's MathFinder!\n";
cout << "It's my first C++ program, so I wanted to \nsee "<<
"if you guys liked it, and if I did well.\n\n\n";
}


int main()
{

unsigned long Width, Height, Base, Width2, Length2;
Welcome();

enum mathType {Area, Volume, Perimeter};

mathType Math;
int x;

start://label

cout << "What math type would you like?(0-2) Area is 0, Volume is 1, and Perimeter is 2.\r\n";
cin >> x;
Math = mathType(x);

if (Math == Area)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\r\n";
return 1;
}

cout << "Enter Width then Length:" << "\r\n";
cin >> Width;
cin >> Height;
cout << "Area is: " << Width * Height << endl;
}


else if (Math == Volume)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\r\n";
return 1;
}

cout << "Enter Width, then Height, then Base:\r\n";
cin >> Width;
cin >> Height;
cin >> Base;
cout << "Volume is: " << Width * Height * Base << endl;
}

else if (Math == Perimeter)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\r\n";
return 1;
}

cout << "Enter Width, then Length.\r\n";
cin >> Width;
cin >> Height;

Width2 = Width * 2;
Length2 = Height * 2;

cout << "Perimeter is: " << Width2 + Length2 << endl;
}

else
goto start; //go to label

return 0;
}


OR THIS:


#include <iostream>
using std::cout;
using std::cin;
using std::endl;

enum mathType {Area, Volume, Perimeter};

void Welcome();//
void Operation(mathType );//function headers

int main()
{
Welcome();
mathType Math;

int x;
DoSomeMath://label

cout << "What math type would you like?(0-2) \n"<<
"Area is 0, Volume is 1, and Perimeter is 2.\n";
cin >> x;

if (x < 0 || x > 2)
goto DoSomeMath;

Math = mathType(x);
Operation(Math);

return 0;
}

void Welcome()
{
cout << "\nWelcome to Vinyl Scratch's MathFinder!\n";
cout << "It's my first C++ program, so I wanted to \nsee "<<
"if you guys liked it, and if I did well.\n\n\n";
}

void Operation(mathType MATH)
{
unsigned long Width, Height, Base, Width2, Length2;

if (MATH == Area)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\n";
return;
}

cout << "Enter Width then Length:" << "\n";
cin >> Width;
cin >> Height;
cout << "Area is: " << Width * Height << endl;
}
else if (MATH == Volume)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\r\n";
return;
}

cout << "Enter Width, then Height, then Base:\r\n";
cin >> Width;
cin >> Height;
cin >> Base;
cout << "Volume is: " << Width * Height * Base << endl;
}
else if (MATH == Perimeter)
{
if (!cin.good())
{
cout << "Invalid Character, please input an integer.\r\n";
return;
}

cout << "Enter Width, then Length.\r\n";
cin >> Width;
cin >> Height;

Width2 = Width * 2;
Length2 = Height * 2;

cout << "Perimeter is: " << Width2 + Length2 << endl;
}
}


Someone did message me though and said that using labels isn't such a swell idea and I see why now. Labels just aren't as solid as using for/while loops. So if you want, you can go ahead and implements some while loops.

gl


while loop:

#include <iostream>
#include <sstream>
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::stringstream;

enum mathType {Area, Volume, Perimeter};

mathType Getx ();
void Welcome();
void Operation(mathType );

int main()
{
Welcome();

Operation(Getx());

return 0;
}

mathType Getx()
{
int x;
string input = "";

while (1)
{
cout << "What math type would you like?(0-2) \n"<<
"Area is 0, Volume is 1, and Perimeter is 2.\n";
getline(cin, input);

stringstream CatchBad(input);

if ((CatchBad >> x))
{
if (x < 0 || x > 2)
continue;
else
break;
}
else
cout << "\nInvalid Character, please input an integer.\n";
}
return mathType(x);
}

void Welcome()
{
cout << "\nWelcome to Vinyl Scratch's MathFinder!\n";
cout << "It's my first C++ program, so I wanted to \nsee "<<
"if you guys liked it, and if I did well.\n\n\n";
}

void Operation(mathType MATH)
{
unsigned long Width, Height, Base, Width2, Length2;

if (MATH == Area)
{
cout << "Enter Width then Length:" << "\n";
cin >> Width;
cin >> Height;
cout << "Area is: " << Width * Height << endl;
}

else if (MATH == Volume)
{
cout << "Enter Width, then Height, then Base:\n";
cin >> Width;
cin >> Height;
cin >> Base;
cout << "Volume is: " << Width * Height * Base << endl;
}

else if (MATH == Perimeter)
{
cout << "Enter Width, then Length.\n";
cin >> Width;
cin >> Height;

Width2 = Width * 2;
Length2 = Height * 2;

cout << "Perimeter is: " << Width2 + Length2 << endl;
}
}

Brandon

2013-01-17 17:53:55

:) I left you that +1 Reputation for the idea but suggested not to use Goto because if used incorrectly, it "skips".. By that I mean, if a variable X already contains input and a user uses a goto statement before that X, rather than asking for input again in a loop, the goto will not even bother asking for input.. Instead, it skips the asking and keeps the previously stored value..

Also, if a bad-bit/flag is set (especially on a stream), it will NOT initialize a new stream or clear the bit.. It will continue on without any errors or letting the user know there is a problem.. The state of the stream stays the same!

Streams like cin and cout will stay the same.. cin will not clear, it will contain the same input it had before and rather than ask for new input, it will use what it already has.. Goto in ASM is a bit different.

Goto can be used in C/C++ but use it carefully and wisely or else you'll end up with trouble. There is almost no situations other than insane nested loops where goto would be required to break out/jump abruptly.

Dijkstra also gave a reason why it's bad.. You can google it for more information on why it should be used with care/rarely.

Echo_

2013-01-17 18:11:58

From: [Re]cUrSivE
  
if (MATH == Area)
{
cout << "Enter Width then Length:" << "\n";
cin >> Width;
cin >> Height;
cout << "Area is: " << Width * Height << endl;
}

else if (MATH == Volume)
{
cout << "Enter Width, then Height, then Base:\n";
cin >> Width;
cin >> Height;
cin >> Base;
cout << "Volume is: " << Width * Height * Base << endl;
}

else if (MATH == Perimeter)
{
cout << "Enter Width, then Length.\n";
cin >> Width;
cin >> Height;

Width2 = Width * 2;
Length2 = Height * 2;

cout << "Perimeter is: " << Width2 + Length2 << endl;
}
}


You can use switch statements with enumerations since they are integer constants, it makes this snippet cleaner too:

switch (MATH) {
case Area:
cout << "Enter Width then Length:" << "\n";
cin >> Width;
cin >> Height;
cout << "Area is: " << Width * Height << endl;
break;

case Volume:
cout << "Enter Width, then Height, then Base:\n";
cin >> Width;
cin >> Height;
cin >> Base;
cout << "Volume is: " << Width * Height * Base << endl;
break;

case Perimeter:
cout << "Enter Width, then Length.\n";
cin >> Width;
cin >> Height;

Width2 = Width * 2;
Length2 = Height * 2;

cout << "Perimeter is: " << Width2 + Length2 << endl;
}

Vinyl Scratch

2013-01-17 19:59:42

Thanks, guys! I know alot more, and when I need to refer back to here, I'll have the information here so that I can understand. You guys are great!

Recursive

2013-01-17 21:58:31

Btw Vinyl Scratch, if you are interested in the math aspect of programming, join project euler. Project euler is very helpful and I'd say I learned a lot of programming by solving problems there. I think my sig contains a link or you can just type in http://projecteuler.net/problems. My friend code is 26216094381320_b3d58f83f92949f0e5e0f71e3fc6122d. Add me if you join

From: Echo_
You can use switch statements with enumerations since they are integer constants, it makes this snippet cleaner too:


You know I tried doing that, but I got some error. So I just decided to stick to what I was doing

tehq

2013-01-17 23:59:23

From: [Re]cUrSivE
Btw Vinyl, if you are interested in the math aspect of programming, join project euler. Project euler is very helpful and I'd say I learned a lot of programming by solving problems there. I think my sig contains a link or you can just type in http://projecteuler.net/problems. My friend code is 26216094381320_b3d58f83f92949f0e5e0f71e3fc6122d. Add me if you join


I'd also recommend Project Euler for learning any programming language. Question 1 with Simba ;)


program One;
{
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
}

var
i, totalsum: integer;
Fin, Fin2: extended;
ArrFin, ArrFin2, SumArr, counted: array of integer;

Function NoRemain(FirstNum, SecondNum: extended): boolean;
begin
Fin := (FirstNum / SecondNum);
Fin2 := Round(Fin);
if (Fin = Fin2) then
Result := true;
end;

begin
SetLength(ArrFin, 1050);
SetLength(Arrfin2, 1050);
SetLength(Counted, 2100);
for i := 0 to 999 do
begin
if (NoRemain(i, 5) = true) then
ArrFin[i] := round((Fin) * 5);
end;
for i := 0 to 999 do
begin
if (NoRemain(i, 3) = true) then
ArrFin2[i] := round((Fin) * 3);
end;
SumArr := CombineIntArray(ArrFin, Arrfin2);
for i := 0 to (Length(SumArr) - 1) do
if InIntArray(Counted, SumArr[i]) then
Totalsum := TotalSum
else
begin
TotalSum := Totalsum + SumArr[i];
Counted[i] := SumArr[i];
end;
ClearDebug;
WriteLn('Sum: ' + IntToStr(TotalSum));
end.

Echo_

2013-01-18 00:51:34

From: tehq
I'd also recommend Project Euler for learning any programming language. Question 1 with Simba ;)


program One;
{
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
}

var
i, totalsum: integer;
Fin, Fin2: extended;
ArrFin, ArrFin2, SumArr, counted: array of integer;

Function NoRemain(FirstNum, SecondNum: extended): boolean;
begin
Fin := (FirstNum / SecondNum);
Fin2 := Round(Fin);
if (Fin = Fin2) then
Result := true;
end;

begin
SetLength(ArrFin, 1050);
SetLength(Arrfin2, 1050);
SetLength(Counted, 2100);
for i := 0 to 999 do
begin
if (NoRemain(i, 5) = true) then
ArrFin[i] := round((Fin) * 5);
end;
for i := 0 to 999 do
begin
if (NoRemain(i, 3) = true) then
ArrFin2[i] := round((Fin) * 3);
end;
SumArr := CombineIntArray(ArrFin, Arrfin2);
for i := 0 to (Length(SumArr) - 1) do
if InIntArray(Counted, SumArr[i]) then
Totalsum := TotalSum
else
begin
TotalSum := Totalsum + SumArr[i];
Counted[i] := SumArr[i];
end;
ClearDebug;
WriteLn('Sum: ' + IntToStr(TotalSum));
end.


Question 1 with Clojure:
(println "sum:" (reduce + (set (concat (range 0 1000 3) (range 0 1000 5)))))

:spot:

Recursive

2013-01-18 01:33:04

I solved questions 1-5 with javascript on khanacademy then for the most part I use c/c++ or bash/awk

Vinyl Scratch

2013-01-20 12:18:21

I'll use Project Euler, then! Thanks!

Vinyl Scratch

2013-02-02 01:08:11

#include <iostream>

using namespace std;

void Math()
{
unsigned long Width, Height, Length, Lateral, Length2, Width2, LengthAndWidth, Area, Total, AreaTimesTwo;

cout << "Enter the length, then width then height\r\n";
cin >> Length;
cin >> Width;
cin >> Height;
Length2 = Length * 2;
Width2 = Width * 2;
LengthAndWidth = Length2 + Width2;
Lateral = LengthAndWidth * Height;
Area = Width * Length;
AreaTimesTwo = Area * 2;
Total = Lateral + AreaTimesTwo;

cout << "Your Lateral is:" << Lateral << endl;
cout << "Your total Surface Area is:" << Total << endl;

}

int main()
{
start:

Math();

goto start;

return 0;
}