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;
}

Edited 1 Year Ago by deceptikon: Moved to C++ forum

  • 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

Edited 1 Year Ago by Florin_1: not double post

This question has already been answered. Start a new discussion instead.