Search code examples
cprintfputs

String not getting printed


I have been trying to solve a problem, Everything works fine, except that the required string is not getting printed

#include<stdio.h>
int main()
{
int test,i,number,num1;

char ch;
scanf("%d",&test);
for(i=test;i>0;i--)
{
    scanf("%d",&number);

    num1=number;

    while(num1>12)
    {
        num1-=12;
    }

    if(num1>0 && num1<7)
    printf("%d ",(2*(6-num1)+1)+number);


    else
    printf("%d ",number-(2*(num1-7)+1));


    if(num1==(1 || 6 || 12 || 7 ))
    {
        puts("WS");
    }

    if(num1==(2|| 5 || 8 || 11))
    {
        puts("MS");
    }

    if(num1==(3 || 4 || 9 || 10))
    { 
       puts("AS");
    }
    }


return 0;
}

Here along with a numeric value, corresponding AS, WS or MS is required to be printed, but after printing the numeric value, the code just ends there, I've also tried other things but none of those worked. Other things which I tried are: 1) Used a character array to store AS, WS or MS and then printing with printf. 2)Used just a character and stored just A, W or M in it and print them along with S already present in the printf function. In this method, S was getting printed but A, W or M wasn't.


Solution

  • I dont't think that you have a problem with puts or printf. I think you just have to write your if or clauses as

    if(num1==1 || num1==6 || num1==12 || num1==7 )
    

    rather than.

    if(num1==(1 || 6 || 12 || 7 ))
    

    See eg. logical or