I recently received an 'A' on a program I submitted for the programming course I'm currently taking.
I'm on spring break and I was hoping to use my spare time to do some studying, so I took my 'A' program and tried to run it in Visual Studio Express, and at first it ran exactly the way it had in the computers on campus. But as soon as it completed the program, the cmd window closed without allowing me time to examine the results.
I made no changes to the program, but please feel free to examine it below. I think the problem has something to do with Visual Studio. But I don't know what.
Please help?
// This program solves problems :)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int choice;
double
pi = 3.14159,
radius,
length,
width,
height,
base,
area;
// Diplay menu and get choice
cout << "\t\t\tPKGEOCALC Attempt #256-1\n\n";
cout << "This program (Hopefully!) calculates the area of a given shape.\n";
cout << "Please enter the number choice for the shape you wish to know the area of.\n\n";
cout << "1. Circle\n\n";
cout << "2. Rectangle\n\n";
cout << "3. Triangle\n\n";
cout << "Which program would you like to run? ";
cin >> choice;
// Repond to the User's choice
if(choice==1)
{
// Enter values for Circle
cout << "\n\nWhat is the radius? ";
cin >> radius;
// Calculate and diplay the solution
area = pow(pi * radius, 2);
cout << "\n\nThe area of your circle is " << area << endl << endl;
}
else if(choice==2)
{
// Enter values for Rectangle
cout << "\n\nWhat is the length of the rectangle? ";
cin >> length;
cout << "What is the width of the rectangle? ";
cin >> width;
// Solve and display result
area = length * width;
cout << "\n\nThe area of your rectangle is " << area << endl << endl;
}
else if(choice==3)
{
// Enter values for Triangle
cout << "\n\nWhat is the base of the triangle? ";
cin >> base;
cout << "What is the height of the triangle? ";
cin >> height;
// Solve and display result
area = (base * height) / 2;
cout << "\n\nThe area of your triangle is " << area << endl << endl;
}
else if(choice==42)
{
cout << "\n\nYou have entered the ultimate answer to\n\n";
cout << "life,\n";
cout << "the universe,\n";
cout << "and (pretty much) everything.\n\n";
cout << "You deserve a cookie!\nGo buy yourself a cookie and pretend I'm picking up the tab!\n\n";
}
else
{
cout << "\n\n *sigh* Typical human, always wanting choices not in the menu...\n\n";
cout << "The only valid choices are 1, 2, or 3\n";
cout << "Please re-run the program and enter a valid choice...or an easter-egg.\n\n";
cout << "There's a cookie in it for you if you go for the easter-egg!\n\n";
}
return 0;
}