Create a program that will calculate the aspect ratio of your computer screen, given the width
and height in pixels, using the following statements:
int width = 1280;
int height = 1024;
double aspect = width / height;
When you output the result, what answer will you get? Is it satisfactory — and if not, how could
you modify the code, without adding any more variables?
#include<iostream>
using namespace std;
int main(){
int width = 1280;
int height = 1024;
double aspect = width / height;
cout << "aspect ration" << aspect << endl;
return 0;
}
I tried this code but It gave me value “1” .. I couldn’t get the question .. what he meant by satisfactory ? and how can I modify the code without adding any variables ?
You are doing an integer division i.e if width is 3 and height is 2 it’d store 1 instead of 1.5 in
aspect. One of the values should be double to make it a double division. Following should work: