#it does nothing

10 messages · Page 1 of 1 (latest)

barren hedge
#

i wrote this code but it does nothing,why?and how can i fix it?
#include <iostream>
#include <fstream>
using namespace std;

int main() {
ifstream input("maximpar.in");
ofstream output("maximpar.out");

if (!input.is_open() || !output.is_open()) {
    cout << "Eroare la deschiderea fisierelor de intrare/iesire." << endl;
    return 1; // Returneaza cod de eroare
}

int n, numar, maxPar = -1, ap = 0;

input >> n;

for (int i = 1; i <= n; ++i) {
    input >> numar;

    if (numar % 2 == 0) {
        if (numar > maxPar) {
            maxPar = numar;
            ap = 1;
        } else if (numar == maxPar) {
            ap++;
        }
    }
}

if (maxPar != -1) {
    output << maxPar << " " << ap << endl;
} else {
    output << -1 << endl;
}

input.close();
output.close();

return 0;

}

thick wyvernBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

fluid frost
#

honestly step trough it with a debugger to see whats up

barren hedge
#

I run it,but it starts and stops.I saw that maximpar.in is never created,just maximpar.out.idk what to do

barren hedge
#

ye,it says that it exited with error code 0,there isnt't any error,just that the program doesn't do anything,and it should

upbeat lintel
#

The code seems to be perfectly fine tho lenny_think

pearl gyro
#

create the file, put in the numbers you want and it should work