0

So I am trying to write a lotto program where the user input is two integers 0-36 or two colors. After that compare them and if the choose to put numbers and it's a match then it should print 36 else if they choose to put colors and matches it should print 2ggr.

Now I get this error comparison between pointer and integer.

I am new to programming so I would be happy to get some help.

#include <stdio.h>
#include <string.h>

int main()
{
    char a[10];
    char b[10];
    
    scanf("%s %s", a, b);
    
    if (a >= 0 && a <= 36 && b >= 0 && b <= 36)
    {
        if (a == b)
        {
            printf("36ggr");
        }
        else if (
               a == 'Red' 
            || a == 'green' 
            || a == 'black' 
            && b == 'Red' 
            || b == 'green' 
            || b == 'black'
        )
        {
            if (a == b)
            {
                printf("2ggr");
            }
        }
        else
        {
            printf("Inget vinst");
        }
    }
    
    return 0;
}

  
zain ul din
  • 1
  • 1
  • 2
  • 23
Masih MK
  • 5
  • 5
  • 3
    `'Red'` is a *character* constant. A string uses double-quotes, like `"Red"`. – Some programmer dude Dec 31 '22 at 11:49
  • 3
    With that said, you need to use [`strcmp`](https://en.cppreference.com/w/c/string/byte/strcmp) to compare strings in C. – Some programmer dude Dec 31 '22 at 11:50
  • Also, what do you mean by comparing `a` and `b` to `0` and `36`? – bereal Dec 31 '22 at 11:53
  • In order to determine whether the string the user entered represents a number or not, you can use the function [`strtol`](https://en.cppreference.com/w/c/string/byte/strtol). If the user entered a number, that function will also tell you which number the user entered. – Andreas Wenzel Dec 31 '22 at 12:11

0 Answers0