#why is my code wrong?

18 messages · Page 1 of 1 (latest)

trim otter
#

(im new to c++ so sorry if the question is stupid or smth)

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    float i, output;
    cin >> n;
    cin >> m;
    
    if (n == 1) {
        cout << m;
    } else {
        if (n%2 == 1) {
            for (i=-(n/2); i<=n/2-1; i++) {
                if (abs(m) < n) {
                    if (i < 0) {
                        output = i-abs(m);
                    } else {
                        output = i+abs(m)+1;
                    }
                } else {
                    if (i < 0) {
                        output = i;
                    } else {
                        output = i+1;
                    }
                }
                cout << output << " ";
            }
            cout << m;
        } else {
            for (i=-(n/2-1); i<=n/2-1; i++) {
                if (abs(m) < n) {
                    if (i < 0) {
                        output = i-abs(m);
                    } else if (i == 0) {
                        output = 0;
                    } else {
                        output = i+abs(m);
                    }
                } else {
                    output = i;
                }
                cout << output << " ";
            }
            cout << m;
        }
    }
    return 0;
}

this code is supposed to output N unrepeated integers which add up to M
some cases this doesn't work, and the practice website i use won't tell me which cases i get wrong

civic night
trim otter
civic night
#

What website are you using?

trim otter
civic night
#

Hmm okay never heard of that one

trim otter
#

it's the one my school need us to use

merry wraithBOT
#

@trim otter has reached level 1. GG!

civic night
#

And it does not show the test case if it fails?

civic night
#

What about the applications output?

trim otter
civic night
#

How are you supposed to find it then lmao

trim otter
civic night
#

But how does that help if you don't know what case

trim otter
civic night
#

I'd go into a local environment and make some cases yourself and debug them