The screen size of a TV is given by the length of the rectangular diagonal. Traditional TVs come in 4:3 ratio, that is, the ratio of length to width is 4 to 3. This means, if the length is x inches, then the width is (3/4)x. LCD TVs come in 16:9 ratio. Write a program that prompts the user to input the length of the diagonal (in inches) of the screen and allows the user to select which type of TV’s screen length, screen width and screen area the user would like to calculate. Have the program display the desired results.
Source code
#include <iostream>
using namespace std;
int main()
{
cout<<"Enter the length of the Tv in inches: ";
double length;
cin>>length;
cout<<"Choose the type of TV\n1. Traditional TV (4:3)\n2. LCD TV (16:9)\n";
int c;
cin>>c;
double width;
double area;
if (c==1){
width=(3/4.0)*length;
}
else if (c==2){
width=(9/16.0)*length;
}
area=length*width;
cout<<"\nLength: "<<length;
cout<<"\nWidth: "<<width;
cout<<"\nArea: "<<area;
return 0;
}
Output 1
Output 2
Comments
Leave a comment