Calculate the area for the given width and length C++ source code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Calculating the area for the given width and length in C++ programming

To show: C++ programming demonstrating the use of variables in calculating the area for the given width and length

 

// demonstrates the use of variables

#include <iostream>

using namespace std;

 

int main(void)

{

unsigned short int Width = 7, Length;

Length = 10;

 

// create an unsigned short and initialize it with the result of multiplying Width by Length

unsigned short int Area = Width * Length;

 

cout<<"Width:\t"<<Width<<"\n";

cout<<"Length: "<<Length<<endl;

cout<<"Area = Width x Length: \t"<<Area<<"\n";

cout<<"Or Area = "<<Width * Length<<endl;

 

return 0;

}

 

Output example:

 

Width: 7

Length: 10

Area = Width x Length: 70

Or Area = 70

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index