You want to rate a mobile phone, according to the following conditions:

Question:
You want to rate a mobile phone, according to the following conditions:
(i) Price should be less than 1500 AED.
(ii) Screen size should be at least 4 inches
(iii) Weight should be less than 200 gms.
Your ratings are as follows:
5 stars, if all the conditions above are met.
4 stars, if condition (i) and (ii) are met only
3 stars, if condition (ii) and (iii) are met only
2 stars, if condition (i) and (iii) are met only
0 stars, if none of the conditions above are met.

Input the price (int), screen size (double) and weight (int). Output the stars as per the above criteria.


Note:
This is the the correct code after fixing the errors.




#include<iostream>
using namespace std;
int main()
{
int price, weight, stars, result;
double size;

cout<<"Enter the price: ";
cin>>price;
cout<<"Enter the screen size: ";
cin>>size;
cout<<"Enter the weight: ";
cin>>weight;

if ( price <= 1500 && size > 4 && weight<200)
cout<<"5 stars"<<endl;

else if ( price <=1500 && size >4 )
{
cout<<"4 stars"<<endl;
}


else if ( size > 4 && weight<200)
{
cout<<"3 stars"<<endl;
}


else if ( price <= 1500 && weight < 200)
{
cout<<"2 stars"<<endl;
}

else
{
cout<<"0 stars"<<endl;
}

return 0;
}
Last edited on
<= is less than or equal, =< is an error.

>= as well. in general the = is always last for both comparisons and combined assignments
eg
x += 3; // same as x = x+3, but here again, the =+ is an error.


you may want an endl on the 0 stars just for consistency.
you could use * symbol for stars if you wanted to be fancy.

Last edited on
oops i didnt notice that! thankyou so much i appreciate it.
Topic archived. No new replies allowed.