C++ does not make an exe file

Hi I'm trying to make a simple c++ code for my assignment and It won't open CMD or make a txt file it just says checking for existence and asks if I want to build the file if I try again it does the same thing. https://prnt.sc/10b9d5a
Well there's a whole bunch of errors to fix, before you can run anything.
Like line 10 - what's that dangling zero?
And line 32 looks like you're declaring a function INSIDE main.

FWIW, paste all the code here between code tags.
https://www.cplusplus.com/articles/jEywvCM9/
Random fuzzy screenshots don't cut it.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include <fstream>

using namespace std;

struct Sportininkas
{
    bool startas = 0;
    int zaide = 0;
    int sedejo = 0;
};

void skaitymas(Sportininkas sport[]);
void spausdinti(Sportininkas sport[]);

int main()
{
    Sportininkas sport[100];

    skaitymas(sport);
    spausdinti(sport);

    for(int i = 0; i < 100; i++)
    {
        //cout << i << " " << sport[i].startas << " " << sport[i].zaide <<  sport[i].sedejo << endl;
    }

    return 0;
}

    /// duomenu skaitymas
    void skaitymas(Sportininkas sport[])
    {
        ifstream fd("U1.txt");

        int n;
        fd >> n;

        for(int i = 0; i < n; i++)
        {
            int nr, k;
            fd >> nr >> k;

            for (int j = 0; j < k; j++)
            {
                int laikas;
                fd >> laikas;

                if(j == 0 && laikas > 0)
                {
                    sport[nr].startas = 1;
                }

                if(laikas > 0)
                {
                    sport[nr].zaide += laikas;
                }
                else
                {
                    sport[nr].sedejo += laikas;
                }

            }

        }
        fd.close();
    }

    ///rezultatai
    void spausdinti (Sportininkas sport[]);
    {
        ofstream fr("U1rez.txt");

        for (int i = 0; i < 100; i++)
        {
            if(sport[i].startas)
            {
                fr << i << " ";
            }
        }
        int daug = 0;
        int mazai = 0;

        for (int i = 0; i < 100; i++)
        {
            if(sport.[i].zaide > sport[daug].zaide)
            {
                daug = i;
            }
            if(sport.[i].sedejo < sport[mazai].sedejo)
            {
                mazai = i;
            }

        }

        fr << endl <<  daug << " " << sport[daug].zaide << endl;
        fr <<  mazai << " " << abs(sport[mazai].sedejo) << endl;

        fr.close();
    }

but it still should out put error's and stuff but it does nothing and always ask when I want to run it Do you want to build it? if press yes it still does not run and if try again it does the same thing.
Last edited on
L70 - remove the terminating ;. As it's written this is a function declaration - not a function definition.
Have you tried clicking on build messages tab instead?

1
2
3
4
$ g++ -Wall -Wextra -std=c++11 foo.cpp
foo.cpp:71:5: error: expected unqualified-id before ‘{’ token
     {
     ^

There's a trailing ; on line 70



yea tried it already it shows nothing only the build log shows "Checking for existence: C:\Users\just-\Desktop\Krepšinis\main.exe" ok I think I fixed the trailing and still nothing.
Last edited on
Complies, not tried:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <fstream>

using namespace std;

struct Sportininkas
{
	bool startas {};
	int zaide {};
	int sedejo {};
};

void skaitymas(Sportininkas sport[]);
void spausdinti(Sportininkas sport[]);

const size_t szSport {100};

int main()
{
	Sportininkas sport[szSport] {};

	skaitymas(sport);
	spausdinti(sport);

	//for (int i = 0; i < szSport; ++i)
		//cout << i << " " << sport[i].startas << " " << sport[i].zaide <<  sport[i].sedejo << endl;
}

/// duomenu skaitymas
void skaitymas(Sportininkas sport[])
{
	ifstream fd("U1.txt");

	if (!fd) {
		cout << "Cannot open file\n";
		return;
	}

	int n {};
	fd >> n;

	for (int i = 0; i < n; ++i) {
		int nr {}, k {};
		fd >> nr >> k;

		for (int j = 0; j < k; ++j) {
			int laikas {};
			fd >> laikas;

			if (j == 0 && laikas > 0)
				sport[nr].startas = true;

			if (laikas > 0)
				sport[nr].zaide += laikas;
			else
				sport[nr].sedejo += laikas;
		}
	}
}

///rezultatai
void spausdinti(Sportininkas sport[])
{
	ofstream fr("U1rez.txt");
	if (!fr) {
		std::cout << "Cannot open output file\n";
		return;
	}

	for (int i = 0; i < szSport; ++i)
		if (sport[i].startas)
			fr << i << ' ';

	int daug {};
	int mazai {};

	for (int i = 0; i < szSport; ++i) {
		if (sport[i].zaide > sport[daug].zaide)
			daug = i;

		if (sport[i].sedejo < sport[mazai].sedejo)
			mazai = i;
	}

	fr << '\n' << daug << ' ' << sport[daug].zaide << '\n';
	fr << '\n' << ' ' << abs(sport[mazai].sedejo) << '\n';
}


If this doesn't produce the expected output, then you should be the debugger to debug your code by setting break points and stepping through the code to see where the behaviour differs from that expected. When you find this, then you're found an issue to correct.
Last edited on
u1.txt file contains
8 ( this number indicates how many players)
9 5 7 -5 13 -4 11 ( 9 is players Number/name) ( 5 how many times he has played) (7 indicates how much time he played on the field if it's minus he was sitting on the bench)
7 5 -3 12 -5 17 -3
25 7 12 -3 5 -5 7 -5 3
14 5 12 -3 10 -7 8
5 1 -40
33 5 15 -5 9 -3 8
11 5 -12 8 -5 12 -3
13 5 3 -4 25 -5 3
and I know that I should get this
9 13 14 25 33
33 32
5 40

but still, I need to make so the file would create a text file in my folder and It still does not and show errors too
Last edited on
With your data, I get the output as:


9 13 14 25 33 
33 32

 40


which is consistent with that required.

The 'missing' 5 before the final 40 is due to the fact that no value is output in the code! Which value should be output before the final 40?
ok so
9 13 14 25 33 number are those players who played in the first match
33 32 means 33 player played most time in the field
and 5 40 means 5 player spent most time on the bench.
Ok then replace L86 above with:

 
fr << '\n' << mazai << ' ' << abs(sport[mazai].sedejo) << '\n';


which then gives:


9 13 14 25 33 
33 32

5 40


as required.
Ok thanks for fixing the code but it still does not fix my other problem that It won't create the .exe or U1rez.txt file.
move the project. It may not like being on your desktop, try making a folder under c:\folder\... and see if it works there. If you code is all in one file, just make a new folder and project and paste the code over. If its in multiple files, you will need to copy them and add them to the project.
Another thing to check is your AV/Malware settings.

Some products are really paranoid about anything that creates an executable, and will routinely delete/quarantine anything not on a white list.

It's a good idea to create a C:\Users\<<myname>>\Projects directory, then go and tell your AV software to exclude said directory from any kind of scanning.

Hello Th3Luk1z,

To address your question I have a question.

When you finished writing did you just press the "Run" button"?

When I first installed C::B I found the first I had to save the ".cpp" file then build or compile and link the project B4 it would run. Later I managed to make this automatic so that all I had to do is press either "Build and Run" or "run".

After that C:B seems to work when I use it.

Andy
Tried turning of antivirus didin't help, tried saving .cpp file still nothing my whole pc is only in C: partition. with older version it worked but it was still not working like It should.
did you move it off the desktop?
Topic archived. No new replies allowed.