Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I can run this but I think there is still smth wrong here, help pls

+4 votes
asked Aug 14, 2024 by (160 points)
#include <bits/stdc++.h>
using namespace std;

int main() {
   char n;
   cin >> n;
   if(n % 2 == 0){
   cout << "CHAN" ;
}
   else
{
   cout << "LE" ;
}

}

2 Answers

+2 votes
answered Aug 14, 2024 by SABARINADH S R (180 points)

#include <bits/stdc++.h>
using namespace std;

int main() {
    char n;
    cin >> n;
    int num = n - '0'; // Convert char to int
    // Now we can use the modulus operator on the integer value
    if(num % 2 == 0){
        cout << "CHAN";
    } else {
        cout << "LE";
    }
}

Converting Character to Integer: in the below code snippet, it asks us to give input a [char]. Therefore, simply after that specific character is used in the modulus operation. Because only the modulus operator can run over an integer, it first needs to be converted from a character by changing each element in our digit list into its respective integer value. Int by num = n - '0'; Perform Modulus Operation: Once we have got the integer value of character, perform modulus operation and extract that element which will tell you number is odd or even.

commented Sep 7, 2024 by Abhay Priyani (100 points)
hi can we use iostream too ??
0 votes
answered Aug 22, 2024 by Mahidhar Darsi (220 points)
changing the input form char to int will resolve your problem. as we are doing % operation it will be good if we use integer input than string.


#include <bits/stdc++.h>
using namespace std;

int main() {
   int n;
   cin >> n;
   if(n % 2 == 0){
   cout << "CHAN" ;
}
   else
{
   cout << "LE" ;
}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...