0

write a program to request two integer number,x and y. If x falls within the range of -2 and 7, y is either 5 or 10, then the program will display ""within range". Otherwise the program displays "out of range".

2
Contributors
4
Replies
24
Views
3 Years
Discussion Span
Last Post by Syafiq_1
0

Help yes, do it for you no. Please show some proof that you've made an honest attempt to do this homework problem on your own.

0
#include <iostream>
using namespace std;

main()

{
int x;
int y;

cout<<"Enter an integer number : "<<x;
cout<<"Enter an integer number : "<<y;


if((x<7 && x>-2)&&(y=5 || y=10))
  {
    cout<<"within range"<<endl;
}

if (!(x<7 && x>-2)&&(y=5 || y=10))
{
    cout<<"out of range"<<endl;
}

i use codeblock software.. n got error. jus show me in c++ if u cant do codeblock. il convert it. sry im kind of new here ><

0

Two issues:

  1. You never populate x and y. You need to input those values using cin.
  2. The = operator is for assignment. When comparing values, use the == operator.

Compare and contrast:

#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;

    cout << "Enter an integer number : ";
    cin >> x;

    cout << "Enter an integer number : ";
    cin >> y;

    if ((x<7 && x>-2)&&(y == 5 || y == 10))
    {
        cout << "within range" << endl;
    }

    if (!(x<7 && x>-2)&&(y == 5 || y == 10))
    {
        cout << "out of range" << endl;
    }
}

Edited by deceptikon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.