Home > Mobile >  How do i set x to be a negative value if x is positive, and if x is positive how do i set it to be n
How do i set x to be a negative value if x is positive, and if x is positive how do i set it to be n

Time:12-15

I am making an AI/algorithm to find a checker pattern in a 2x2 square. I need them to be negative for hidden_1 and hidden_3, but positive for the other 2.

#include <iostream>
#include <math.h>
#include <string.h>  
    
using namespace std;
    
int main (){
    int x;
    int y;
    int a;
    int b;
    int x1 = -x;
    int y1 = -y;
    int a1 = -a;
    int b1 = -b;
    cout << "Is there a square in the top left?\n1 for Yes/-1 for No\n";
    cin >> x;
    cout << "Is there a square in the bottom right?\n1 for Yes/-1 for No\n";
    cin >> y;
    cout << "Is there a square in the bottom left?\n1 for Yes/-1 for No\n";
    cin >> a;
    cout << "Is there a square in the top right?\n1 for Yes/-1 for No\n";
    cin >> b;


    int hidden_1 << x1   y1   -1;
    int hidden_2 << x   y   -1;
    int hidden_3 << a1   b1   -1;
    int hidden_4 << a   b   -1;

CodePudding user response:

You initialised x1, y1, a1, b1 with negatives of variables that weren't read. Try declare them after you read x, y, a, b.

#include <iostream>
#include <math.h>
#include <string.h>  

using namespace std;

int main () {
  int x;
  int y;
  int a;
  int b;

  cout << "Is there a square in the top left?\n1 for Yes/-1 for No\n";
  cin >> x;
  cout << "Is there a square in the bottom right?\n1 for Yes/-1 for No\n";
  cin >> y;
  cout << "Is there a square in the bottom left?\n1 for Yes/-1 for No\n";
  cin >> a;
  cout << "Is there a square in the top right?\n1 for Yes/-1 for No\n";
  cin >> b;

  int x1 = -x;
  int y1 = -y;
  int a1 = -a;
  int b1 = -b;

  int hidden_1 = x1   y1   -1;
  int hidden_2 = x   y   -1;
  int hidden_3 = a1   b1   -1;
  int hidden_4 = a   b   -1;
  •  Tags:  
  • c
  • Related