int variable not working in if-else statement
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: int variable not working in if-else statement

  1. #1
    Join Date
    Oct 2017
    Posts
    1

    int variable not working in if-else statement

    Here is the code:

    Code:
    else {
            if (month == 4 || month == 6 || month == 9 || month = 11) {
                if (day <= 30) {
                    return true;
                }
                else {
                    return false;
    Here is the error:
    (266): warning C4305: '=': truncation from 'int' to 'bool'
    (266): error C2106: '=': left operand must be l-value

    the first month is underlined but I don't know what is wrong?
    Last edited by 2kaud; October 11th, 2017 at 02:41 AM.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,575

    Re: int variable not working in if-else statement

    Look at the last month comparison to the far right, you have month = 11 instead of month == 11.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,786

    Re: int variable not working in if-else statement

    When posting code, please use code tags. Go Advanced, select the formatted code and click '#'.

    Code:
    if (day <= 30) {
                    return true;
                }
                else {
                    return false;
    Note that this can be shortened to

    Code:
    return day <= 30;
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++17 Compiler: Microsoft VS2017 (15.4.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)