1

I installed, according to a few YT tutorials, the VSCode editor. I also installed the C/C++ extensions, theme and the Code runner extension, and I downloaded from sourceforge the Mingw64 folder, moved it to C:\ and then added the Path to the system variables. Despite this, the compiler can compile c but not c++ (gives me an error like "exited with code -1" or something). I searched up on google and found nothing about this. Does anybody have a solution?

I also tried changing the compiler from gcc.exe to g++.exe in the C/C++ configuration. Nothing changed.

I'm going to put the code I wrote under here. Please ignore the language, I'm not English :)

C code:

#include<stdio.h>

int main(){
    int eta;
    printf("Ciao, inserisci eta: ");
    scanf("%d", &eta);
    printf("L'eta e' %d", eta );
    return 0;
}

C++ code:

#include<iostream>
using namespace std;

int main(){
    float importo, rendcat, incA=0, incB=0, incD=0, mediaAg=0, mediaEd=0, sommaAg=0, sommaEd=0;
    char cat, tipo, ered, nome;
    int percrendcat, aliq, coeffimm, erF=0, erAg=0, erEd=0;
    
    do{
        importo=0;
        rendcat=0;
        percrendcat=0;
        aliq=0;
        coeffimm=0;
        
        cout<<"\nInserire il nome (iniziale): ";
        cin>>nome;
        if(nome!='*'){
            
        do{
            cout<<"\nInserire la rendita catastale: ";
            cin>>rendcat;
            if(rendcat<=0){
                cout<<"\nInserire una rendita maggiore di 0.";
            }
        }while(rendcat<=0);
        
        do{
            cout<<"\nInserire la categoria di immobile: "
                <<"\n[a/A] Categoria A"
                <<"\n[b/B] Categoria B"
                <<"\n[d/D] Categoria D\n";
            cin>>cat;
            switch(cat){
                case 'a':
                case 'A':{
                    coeffimm=120;
                    break;
                }
                case 'b':
                case 'B':{
                    coeffimm=140;
                    break;
                }
                case 'd':
                case 'D':{
                    coeffimm=60;
                    break;
                }
                default:{
                    cout<<"\nOpzione non valida. ";
                    break;
                }
            }
        }while(cat!=65&&cat!=66&&cat!=68&&cat!=97&&cat!=98&&cat!=100);
    
        do{
            cout<<"\nInserire il tipo di immobile: "
                <<"\n[a/A] Casa"
                <<"\n[b/B] Terreno agricolo"
                <<"\n[c/C] Terreno edificabile\n";
            cin>>tipo;
            switch(tipo){
                case 'a':
                case 'A':{
                    percrendcat=5;
                    break;
                }
                case 'b':
                case 'B':{
                    percrendcat=25;
                    coeffimm=90;
                    erAg++;
                    break;
                }
                case 'c':
                case 'C':{
                    percrendcat=30;
                    coeffimm=95;
                    erEd++;
                    break;
                }
                default:{
                    cout<<"\nOpzione non valida. ";
                    break;
                }
            }
        }while(tipo!='a'&&tipo!='A'&&tipo!='b'&&tipo!='B'&&tipo!='c'&&tipo!='C');
        
        do{
            cout<<"\nL'eredit"<<char(133)<<" proviene da: "
                <<"\n[a/A] Genitore"
                <<"\n[b/B] Fratello"
                <<"\n[c/C] Altro parente\n";
            cin>>ered;
            switch(ered){
                case 'a':
                case 'A':{
                    aliq=5;
                    break;
                }
                case 'b':
                case 'B':{
                    aliq=7;
                    erF++;
                    break;
                }
                case 'c':
                case 'C':{
                    aliq=9;
                    break;
                }
                default:{
                    cout<<"\nOpzione non valida. ";
                    break;
                }
            }
        
        }while(ered<65||(ered>67&&ered<97)||ered>99);
        
        importo=(((rendcat+(rendcat*percrendcat/100))*coeffimm)*aliq)/100;
    
        cout<<"\nNome del cittadino (iniziale): "<<nome;
        cout<<"\nImporto da pagare: "<<importo<<" euro.";
        cout<<"\nTipologia di bene selezionata: "<<tipo;
        cout<<"\nValore dell'aliquota applicata: "<<aliq<<"\n";
        
        switch(cat){
            case 'a':
            case 'A':{
                incA=incA+importo;
                break;
            }
            case 'b':
            case 'B':{
                incB=incB+importo;
                break;
            }
            case 'd':
            case 'D':{
                incD=incD+importo;
                break;
            }
        }
        switch(tipo){
                case 'b':
                case 'B':{
                    sommaAg=sommaAg+importo;
                    mediaAg=sommaAg/erAg;
                    break;
                }
                case 'c':
                case 'C':{
                    sommaEd=sommaEd+importo;
                    mediaEd=sommaEd/erEd;
                    break;
                }
            }
            
        cout<<"\nNumero di cittadini che hanno ricevuto eredit"<<char(133)<<" da fratello: "<<erF;
        cout<<"\nIncasso dello stato per immobili di categoria A: "<<incA<<" euro.";
        cout<<"\nIncasso dello stato per immobili di categoria B: "<<incB<<" euro.";
        cout<<"\nIncasso dello stato per immobili di categoria D: "<<incD<<" euro.";
        cout<<"\nIl valore medio delle tasse pagate sui terreni agricoli ammonta a "<<mediaAg<<" euro.";
        cout<<"\nIl valore medio delle tasse pagate sui terreni edificabili ammonta a "<<mediaEd<<" euro.";
        
        }
    
    }while(nome!='*');
    
    cout<<"\n3B software, grazie per aver scelto i nostri programmi.";

    return 0;
}

drescherjm
  • 10,365
  • 5
  • 44
  • 64
  • I need to use mingw for school. Also, in vscode the C/C++ extension is the same one and there isn't a c++ only configuration. – Zaccaria Francescato Oct 25 '22 at 14:24
  • 2
    Is that really the smallest example of C++ that you have problems with? – molbdnilo Oct 25 '22 at 14:24
  • Your C++ program is too long and complicated for the purpose of testing the toolchain. I suggest to replace it with a helloworld or another trivial program (the one you used for C is perfect). Then, since this is VS Code, you should post the content of your launch.json file (and possibly others, but I know it too little to tell you which ones) – Fabio says Reinstate Monica Oct 25 '22 at 14:25
  • 3
    VSCode is not ideal for C++, use the Visual Studio **IDE** as tadman mentioned. *exited with code -1* is because the compiler ran into trouble (segfault or something) and just gave up on you, it is annoying because it's almost impossible to tell what the problem is. You could try to compile a minimal source code, without including anything, just a simple entry point to see if it can be compiled at all. – thedemons Oct 25 '22 at 14:25
  • Sorry, I may have put a too long code. I also tried with other codes and with the simpler "hello world" but nothing changed. – Zaccaria Francescato Oct 25 '22 at 14:27
  • You'd think if this was a requirement they'd tell you how to install it, but some schools just don't care. Hope you can get this working given their constraints! – tadman Oct 25 '22 at 14:31
  • 2
    [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Jesper Juhl Oct 25 '22 at 14:33
  • You need to show the exact and complete message you are getting. "Or something" is no good. "Doctor, my nose fell off or something". Note that you don't need VSCode. You can do everything using a simple editor such as Notepad++ and command line tools. – n. m. could be an AI Oct 25 '22 at 14:34
  • 3
    ***and the Code runner extension, and I downloaded from sourceforge the Mingw64 folder*** My advice is to do neither of these. Instead uninstall both follow the official VSCode recommendations: [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw) – drescherjm Oct 25 '22 at 14:36
  • @thedemons I disagree with your initial statement. It takes a bit more work to get set up, but I've found it to be just fine. It is possible that my world-view is heavily skewed since my work is vim with very few plugins. – sweenish Oct 25 '22 at 14:59

0 Answers0