| | |
Urgent: Need Help Writing Simple Program for length and width
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 13
Reputation:
Solved Threads: 0
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:
C++ Syntax (Toggle Plain Text)
#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
Last edited by Ancient Dragon; Feb 10th, 2009 at 8:34 pm. Reason: add code tags
•
•
Join Date: Feb 2009
Posts: 13
Reputation:
Solved Threads: 0
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
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. Last edited by Comatose; Feb 10th, 2009 at 1:41 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Array help needed
- Next Thread: Client/Server sockets and reading a file
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






