My project closes - any idea?

Hello,

I have a uni project to do. I've completed it but for some reason, when I run it in Visual Studio 2012, it closes at a certain point. I created it in CodeBlocks and it runs fine. The code is:




#include <iostream>

using namespace std;

int main()
{
int choice;
double length, width, area;

cout << "Choose one of the following:\n\n\n";
cout << "1. Calculate the area of a circle\n\n";
cout << "2. Calculate the area of a rectangle\n\n";
cout << "3. Calculate the area of a triangle\n\n";
cout << "4. Quit\n\n";
cout << "Enter your choices: 1-4\n\n";

cin >> choice;

if (choice == 1)
{
double r;
double area;
double pi = 3.14159;

cout << "What is the radius of the circle?";
cin >> r;
area = 3.14159*r*r;
cout << "The area of the circle is " << area;
}



else if (choice ==2)
{


cout << "What is the length of the rectangle?\n";
cin >> length;
cout << "What is the width of the rectangle?\n";
cin >> width;

area = length * width;
cout << "The area of the rectangle is " << area << endl;
}

else if (choice ==3)
{

double base, height;
double area;
cout << "What is the base of the triangle?\n";
cin >> base;
cout << "What is the height of the triangle?\n";
cin >> height;

area = base * height *5;
cout << "The area of the triangle is " << area << endl;
}

else
{


cout << "Wrong number entered!";
}

return 0;
}


When I run it in VS, and I press 1 and enter, it asks the radius of the circle. When I enter the radius of the circle and press enter, it closes. But in codeblocks it doesn't close. It's the same with other options (1,2,3,4) Any help would be appreciated.
Last edited on
See the sticky here:
http://www.cplusplus.com/forum/beginner/1988/

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thanks a lot! I forgot about the system pause thing, ha!
Btw, do you know how to close the program when I press 4? I tried the Exit() thing and it says it's not declared...
Use exit(), not Exit().
Be sure to include <cstdlib>

closed account (LA48b7Xj)
You could just write return 0; to exit the program.
Topic archived. No new replies allowed.