I created a main menu on my program, but when the function is completed, it just closes, even if I put "do" and "while".
Also, there is something wrong in the code? I can't check it because the program closes down everytime.
This program must take numbers in input, and it should be able to output them and make the sum of the rows and the columns, all of this trough a main menu.
Thanks in advance.
Code:
#include<stdio.h>
#include<string.h>
int main(void)
{
int selection;
int matrice[30][30];
int i;
int j;
int m;
int n;
int MAXn;
int vet;
do {
printf
("+----------------------------------------------------------------------------------------------+\n");
printf("1) input \n");
printf("2) view input \n3) sum rows\n4) sum colums \n9) exit\n--->");
scanf("%d", &selection);
if (selection == 1) {
printf("how many numbers will be inserted? ");
scanf("%d", &n);
printf("input a sequence of %d numbers\n", n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
printf("element %d: ", i + 1);
scanf("%d", &matrice[j]);
}
printf("\n");
}
}
if (selection == 2) {
printf("the sequence is the following:\n");
for (i = 0; i < n; i++)
for (j = 0; i < n; j++)
printf("element %d: %d\n", i + 1, matrice[j]);
printf("\n");
}
if (selection == 3) {
int somma;
for (i = 1; i <= n; i++) {
int somma = 0;
for (j = 1; i <= m; i++) {
somma = somma + matrice[j];
printf("sum: %d", &matrice[j]);
}
printf("sum: %d", somma);
}
}
if (selection == 4) {
int somma;
int righe;
int colonne;
int a[10][10];
for (righe = 0; righe < i; righe++) {
somma = 0;
for (colonne = 0; colonne < j; colonne++) {
somma = somma + a[colonne][righe];
}
printf("The sum of Column Elements in a Matrix = %d \n", somma);
}
}
if (selection > 10) // errore
{
printf("your choice is not valid");
}
if (selection == 9) {
printf("Exiting...");
getc;
}
}
while (selection == 9);
}