This is what I have so far :/

#include <iostream>


using namespace std;


int main()
{

    int i;

    for (i = 1; i <= 12; i++)
    {
        cout << i;
        if ((i = 4) && (i = 9)){
            cout << " \n";
        }
        else {
            cout << endl;
        }
    }










    system("pause");
    return 0;
}

Recommended Answers

All 7 Replies

It just loops number 10 for some reason

Member Avatar for jencas

(i = 4) && (i = 9) does not do what you think it does

  • As was noted, you're using the assignment operator(=) not the equality operator(==) to test for the numbers you want to exclude.

  • Also your description says you want to exclude 2 and 9 but your code seems to indicate 4 and 9.

  • Your logic is a bit skewed line 14(cout << i;) should be part of line 19(cout << i << '\n';).

I changed everything to this

#include <iostream>


using namespace std;


int main()
{

    int i;

    for (i = 1; i <= 12; i++)
    {
        if ((i == 2) && (i == 9)){
            cout << " \n";
        }
        else {
            cout << i << '\n';
        }
    }










    system("pause");
    return 0;
}

still... it doesn't exclude 2 and 9

cout << " \n"; doesn't include it because it's printing only an empty line on that statement?

Oh wait, why are you using && operator? i cannot be 2 and 9 at the same time ... did you mean ||?

#include <iostream>
using namespace std;
int main()
{
    int i;
    for (i = 1; i <= 12; i++)
    {
        if ((i == 2) || (i == 9)){
            cout << " \n";
        }
        else {
            cout << i << '\n';
        }
    }
    return 0;
}

OMG... my teacher said it means "and" for some reason.

EDIT: This works! thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.