Brand new to c++ and need help with a school task

Hello, I have to ask a user to enter integers or to enter q to quit. I have written a program that finally allows the user to enter q without the program entering an infinite loop. Now I am unable to enter the number 0 without triggering my break.

How can I allow the user to enter 0 so that it applies towards total and q to quit the program?

This is for a midterm and has to remain simple.

Thank you

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int integer = 0;
    int count = 0;
    int total = 0;
    int odd = 0;

    do
    {
        cout << "Enter integer (q to quit): ";
        cin >> integer;
        if (integer == false)
        {
            break;
        }
        if (integer % 2 == 1)
        {
          cout << "we have an odd" << "\n";
          odd++;
          total += integer;
        }
        
    } while (integer == true || integer >= 0 || integer <= 0);
    
    cout << "Odd = " << odd << endl;
    cout << "Total = " << total << endl;
    cout << "Goodbye!";
    
   
return 0;
}
cout << "Enter integer (q to quit): ";

read as a string, see if it is == "q" and if not, convert it to an integer after that and use it. you can convert to an integer with stoi().
Apologies for the cross-post. I wasn't aware that it is something looked down upon. I did not mean to waste anyone's time and I appreciate the help I received.

Thanks again
Unless I misunderstand, the issue of cross posting is associated with a rash of posts from users with 1 or 2 posts in their count which actually pose as genuine questions, but become the source of spam links, and sometimes represent vague questions which waste participants' time.

In other words, I don't think it is really that the post appears on another board, but that we've had a bunch of offensive spoilers that do that.
that and some people post the same thing in like beginner and general on this site, which makes a bit of a mess. Its not a big deal as a new (legit) member.
The problem with cross-posting is that it makes two+ people do redundant work to try to help you, needlessly wasting one or more of their times. It's just selfish to do. At least, if you do it, make it clear that you also asked the same question [in link here], so that people can know if the guy has already been helped, and not waste their times.

(Separate issue from spam itself, but cross-posted posts can be a sign of spam; it's a case-by-case basis.)
Last edited on
Topic archived. No new replies allowed.