I am VERY new to C++ and was wondering if someone could help me write this program. I am trying to find the area and perimeter of a rectangle. The length is 10 and the width is 12. Area = length * width (i am presuming) and Permiter would = 2 * length + 2 * width.
#include <iostream>
#include <conio.h>
usingnamespace std; //declare this so that you should be able to use "cout" and "cin"
int main() //this an important fucntion
{
int length = 10;
int width = 12;
int Area = length * width;
int Perimeter = 2*length + 2*width;
cout << "Area = " << Area <<endl;
cout << "Perimeter = " << Perimeter;
getch();
return 0;
}
can anyone else please try to explain to mike?????
Firstly you would need to include the "<iostream>" header, for the output functions, & "conio.h" for the getch function
Next "using namespace std;" for using functions within the namespace "std" without having to write std::func_name.
Declare the "main" function of the program, which returns an integer, so is done using the integer keyword. "int main() { ... }"
Then we need to declare the length, width, area & perimeter of the rectangle, in this example they are all whole numbers (integers), so we use the "int" keyword, then use "=" to set a value to them.
The cout function then prints text within "quotation marks" or variables without quotation marks.
The variable endl is for a newline.
Use the getch function to wait for user to press enter.
Return 0, as the main function returns an integer.