Post

Replies

Boosts

Views

Activity

xcode crashes after trying to build my code for a second time
Hello, I have recently started coding in c++, using xcode's command line tool (university project). Ever since I started using this Apple made app on my 2022 macbook air M2, I am battling a major issue. Every time I try to either build my project for the second time or to clear the console, after I have made some input through the console, the Xcode crashes. I've been looking for the solution for weeks now, even reinstalled the whole xcode app, but nothing helped. I will be very much grateful for any suggestions... thanks. Here is one of my codes, where the issue appears: // Hlavickove soubory #include <stdlib.h> // Standardni knihovna #include <stdio.h> // Standardni input, output #include <math.h> // Matematicka knihovna #define N_MAX 100 // Samotny program int main() // Zahlavi hlavni funkce { int n, max, i, souradnice_je_0; // Definice promennych a jejich nastaveni do vychozich hodnot float a[N_MAX], ap, gp, hp; souradnice_je_0 = 1; max = 100; ap = 0; gp = 1; hp = 0; Znovu: printf("\n Zadej dimenzi vektoru n: "); scanf("%i", &n); // Zadani poctu dimenzi if(n>N_MAX) // Osetreni maxima dimenzi { printf("\n Chyba v datech: Zadaná dimenze n musí být menší než %i", max); goto Znovu; } else if(n<=0) // Osetreni kladnosti dimenzi { printf("\n Chyba v datech: Zadaná dimenze n musí být větší než 0"); goto Znovu; } else { if(n == 1) // Kontrola gramatiky:Dd { printf("\n Vektor má %i dimenzi", n); } else if(n>1 and n<5) { printf("\n Vektor má %i dimenze", n); } else { printf("\n Vektor má %i dimenzí", n); } } for(i = 0; i < n; i++) // Zadani souradnic vektoru { printf("\n Zadej hodnotu x[%i] souřadnici vektoru: ", i); scanf("%f", &a[i]); printf("x[%i] = %g",i, a[i]); if(a[i] == 0) // Kontrola zda a[i] je 0 kvuli h.p. { ap = ap + a[i]; // Arit. prumer 1. cast gp = gp * a[i]; // Geom. prumer 1. cast souradnice_je_0 = 0; // Switch kvuli deleni nulou } else { ap = ap + a[i]; // Arit. prumer 1. cast gp = gp * a[i]; // Geom. prumer 1. cast hp = hp + (1 / a[i]); // Harm. prumer 1. cast } } if(hp==0) { souradnice_je_0 = 0; // Switch kvuli deleni nulou } ap = ap /n; // Arit. prumer 2. cast printf("\n Aritmeticky prumer je: %g", ap); if(gp>=0) // Nelze odmocnit zaporne cislo { gp = pow(gp, 1./n); // Geom. prumer 2. cast } if(gp>=0) { printf("\n Geometricky prumer je: %g", gp); } else { printf("\n Geometricky prumer neni pro zadany vektor definovan"); } if(souradnice_je_0 == 0) { printf("\n Harmonicky prumer neni pro zadany vektor definovan \n"); } else { hp = n / hp; // Harm. prumer 2. cast printf("\n Harmonicky prumer je: %g \n", hp); } return 0; }
3
0
515
Nov ’23