Monitor Dimensions Calculator in C++

July 22, 2018

decided to do a "practical" application that turned out to be much simpler than i expected:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int horizontalPixels;
int verticalPixels;
double diagonalInches;
double pythagA;
double pythagB;
double pythagC;
double theorem;
double divisor;
double sideA;
double sideB;
double temp;

cout << "Enter horizontal pixel count: ";
cin >> horizontalPixels;
cout << "Enter vertical pixel count: ";
cin >> verticalPixels;
cout << "Enter the diagonal measurement in inches: ";
cin >> diagonalInches;

pythagA = pow(horizontalPixels, 2);
pythagB = pow(verticalPixels, 2);
theorem = pythagA + pythagB;
pythagC = sqrt(theorem);
divisor = pythagC / diagonalInches;
sideA = horizontalPixels / divisor;
sideB = verticalPixels / divisor;

cout << "Horizontal measurement: " << sideA << " inches" << endl;
cout << "Vertical measurement: " << sideB << " inches" << endl;

return 0;
}

Sharing:

Categories

Subscribe to landwarinasia.net

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply

Recent Posts

    Contact Me: