I have written the program but I do not know if the results are correct. This is my Declaration: length width area and perimeter. My Input is length and width. The calculations are p=2*(l+w) and a=l*w. My Output is P and A. So what i want to know is, are these the correct results when the program is ran because i do not think so. here is the program:

#include <iostream>
using namespace std;

int main()
{

  int length, width;
  int perimeter, area;              // declarations
  cout <<  "Length = ";             // prompt user
  cin >> length;                    // enter length
  cout << "Width = ";               // prompt user
  cin >> width;                     // input width
  perimeter = 2*(length+width);     // compute perimeter
  area = length*width;              // compute area
  cout << endl
       << "Perimeter is  " << perimeter;
  cout << endl
       << "Area is " << area
       << endl;                    // output results
} // end of main program
Comments
This doesn't seem urgent...

but when i run it, it asks for length (then i type a random number and hit enter) then it asks for width (and i type a random number and hit enter) but then it just closes and thats it. If its possible can you please copy paste and run it so u can see what im talking about. I have this as my first assignment in my class due today at 12 30 Thanks

First, you don't want your instructor to know that you simply copied the code from this web page. Getting assistance by using the page is one thing.... basically plagiarizing the code is another altogether. However, the output is correct, and the program does work.

The reason it is likely "just closing" is because you are running this through a GUI of some kind, that launches the code, and exits (hence, closing the otuput window). You can run this through a command line, or put a cin.ignore() just before the return 0; (which you don't have, but should have as the last line before the ending }). If one cin.ignore() doesn't work, try two.

Comments
well spotted that it was a copy!!!

Hi,

Try Using,
[
system("pause");
return 0;
]
Just before the end of the program (last curly bracket)

Comments
Please Stop Suggesting The Use Of This Trash....
This article has been dead for over six months. Start a new discussion instead.