Trouble with setting values, reading and printing bi-dimensional arrays

0
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <locale.h>

main () {

setlocale(LC_ALL,"Portuguese");

int QntSubs, escolha, mF, eF, iF, ispMotor, qF, contagem, i, x; //mudarfoguete, excluir foguete, informaçao do foguete, massa do motor, qual foguete

float foguetes[1000][2], dV, mCheia, mVazia, mMotor;

    do {

    printf ("\n1-Cadastrar os dados de um foguete"); // enter rocket values (dry and wet masses)
    printf ("\n2-Mudar os dados de um foguete já inserido"); // change rocket values (dry and wet masses)
    printf ("\n3-Excluir os dados de um foguete já inserido"); // delete rocket values (dry and wet masses)
    printf ("\n4-Listar os foguetes já cadastrados"); // list registered rockets (dry and wet masses)
    printf ("\n5-Incluir dados do motor substituto"); // enter substitute engine values (Total mass and Isp)
    printf ("\n6-Realizar cálculo de dV\n\n"); // calculate deltaV

    scanf ("%d", &escolha);
    fflush (stdin);

    switch(escolha) {

        case 1:

            printf ("\nQuantos foguetes serão cadastrados?: "); // how many rockets do you want to register?
            scanf ("%d", &x);

            for (contagem=x; contagem > 0; contagem --) {

                printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
                scanf ("%f", &mCheia);

                printf ("Massa do estagio vazio(kg): "); // dry Mass
                scanf ("%f", &mVazia);

                foguetes[x][1] = mCheia;
                foguetes[x][2] = mVazia;


               }

        break;

        case 2:

            printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
            scanf ("%f", &mCheia);
            fflush (stdin);

            printf ("\nMassa do estagio vazio(kg): "); // Dry Mass
            scanf ("%f", &mVazia);
            fflush (stdin);

            printf ("\n\nQual foguete você deseja mudar?:"); // Which rocket shall be changed?
            scanf ("%d", &mF);


            foguetes[mF][1] = mCheia;
            foguetes[mF][2] = mVazia;

        break;

        case 3:

             printf ("\n\nQual é o número do foguete que você deseja excluir?: "); // Which rocket shall be deleted?
             scanf ("%f", &eF);
             fflush (stdin);

             foguetes[eF][1] = 0;
             foguetes[eF][2] = 0;

        break;

        case 4:

            printf ("\n\nQual foguete você deseja ver as informações?: "); // Which rocket's values shall be showed?
            scanf ("%f", &iF);

            printf ("Massa Cheis (kg): %f", foguetes[iF][1]);
            printf ("Massa Vazia (kg): %f", foguetes[iF][2]);

        break;

        case 5:

            printf ("\n\nMassa total dos motores: "); // Engines total mass
            scanf ("%f", &mMotor);
            fflush (stdin);

            printf ("\n\nEficiência dos motores(Isp): "); // Engine efficiency (Isp)
            scanf ("%f", &ispMotor);
            fflush (stdin);

        break;

        case 6:
            printf ("\n\nPara qual foquete você quer calcular o dV? "); // Which rocket's deltaV shall be calculated?
            scanf ("%f", &qF);
            fflush (stdin);

            dV = (ispMotor * 9.80665 * log((mCheia + mMotor)/(mVazia + mMotor)));

        break;

        default:
            printf("\nOpção inválida. Por favor escolha um ação de 1-6 ou 0 para finalizar o programa.\n"); // Invalid option. Please choose an action between 1-6 or 0 to end the process

        }
    } while(escolha > 0);

    return(0);

    exit;

}

Hello. I'm having a hard time with the array **foguetes[1000][2] in general. I think a rundown of what happens in which of the switch/cases will be the best way to explain my problems. I get no errors, only the warning "return type defaults to 'int' (-Wimplicit-int)"

case 1: Everything is apparently fine. No errors.

case 2: Since the process is basically the same as in case 1, but for selecting a specific line and column to change, everything is also apparently fine.

case 3: Running the code, setting values with case 1 or 2, then using case 3 to set those values (user-defined line and column) to zero returns "Process returned -1073741819 (0xC0000005)". How can this be solved?

case 4: This case is supposed to display the values of column 1 (mCheia // wet mass) and column 2 (mVazia // dry mass), each value printed by a printf. When I set values of mCheia and mVazia for 2 lines of foguetes[1000][2], the info for 2 rockets, and use case 4 to list them, I get to situations: 1) The first rocket I register using case 1 returns "Process returned -1073741819 (0xC0000005)", whether I use case 1 or 2 to set the values. 1) The second rocket I register using case 1 returns "Massa Cheis (kg): 0,000000Massa Vazia (kg): 0,000000", even though I used the values 200 for mCheia and 20 for mVazia in case 1.

case 5: I don't see why this wouldn't work since I'm not using arrays here, but haven't tested it.

case 6: This is the section that I have yet to write properly. My intention is using lines 110-112 to get which line of the array will be select by the user, then use this information to get two specific values, one for mCheia (column 1 // wet mass) and one for mVazia (column 2 // dry mass). I will then put those values inside of the equation dV and display the value of dV to the user. Something along these lines:

dV = (ispMotor * 9.80665 * log((foguetes[qF][1] + mMotor)/(foguetes[qF][2] + mMotor)));

Is the syntax of the line above correct? If not, what is the correct syntax?

Thank you for reading and sorry for any mistakes.

Edit: Would this be better for case 1?

for (contagem=0; contagem <x; contagem ++) {

                printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
                scanf ("%f", &mCheia);

                printf ("Massa do estagio vazio(kg): "); // dry Mass
                scanf ("%f", &mVazia);

                foguetes[contagem][1] = mCheia;
                foguetes[contagem][2] = mVazia;

}

Edit 2:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <locale.h>

int main (void) {

setlocale(LC_ALL,"Portuguese");

int QntSubs, escolha, mF, eF, iF, ispMotor, qF, contagem, i, x; //mudarfoguete, excluir foguete, informaçao do foguete, massa do motor, qual foguete

float foguetes[1000][2], dV, mCheia, mVazia, mMotor;

    do {

    printf ("\n1-Cadastrar os dados de um foguete"); // enter rocket values (dry and wet masses)
    printf ("\n2-Mudar os dados de um foguete já inserido"); // change rocket values (dry and wet masses)
    printf ("\n3-Excluir os dados de um foguete já inserido"); // delete rocket values (dry and wet masses)
    printf ("\n4-Listar os foguetes já cadastrados"); // list registered rockets (dry and wet masses)
    printf ("\n5-Incluir dados do motor substituto"); // enter substitute engine values (Total mass and Isp)
    printf ("\n6-Realizar cálculo de dV\n\n"); // calculate deltaV

    scanf ("%d", &escolha);
    fflush (stdin);

    switch(escolha) {

        case 1:
            printf ("\nQuantos foguetes serão cadastrados?: "); // how many rockets do you want to register?
            scanf (" %d", &x);

            for (contagem=0; contagem <x; contagem ++) {

                printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
                scanf (" %f", &mCheia);

                printf ("Massa do estagio vazio(kg): "); // dry Mass
                scanf (" %f", &mVazia);

                foguetes[contagem][0] = mCheia;

                foguetes[contagem][1] = mVazia;
            }
        break;

        case 2:
            printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
            scanf (" %f", &mCheia);
            fflush (stdin);

            printf ("\nMassa do estagio vazio(kg): "); // Dry Mass
            scanf (" %f", &mVazia);
            fflush (stdin);

            printf ("\n\nQual foguete você deseja mudar?:"); // Which rocket shall be changed?
            scanf (" %d", &mF);

            foguetes[mF][0] = mCheia;
            foguetes[mF][1] = mVazia;
        break;

        case 3:
             printf ("\n\nQual é o número do foguete que você deseja excluir?: "); // Which rocket shall be deleted?
             scanf (" %f", &eF);
             fflush (stdin);

             foguetes[eF][0] = 0;
             foguetes[eF][1] = 0;
        break;

        case 4:
            printf ("\n\nQual foguete você deseja ver as informações?: "); // Which rocket's values shall be showed?
            scanf (" %f", &iF);

            printf ("Massa Cheis (kg): %f", foguetes[iF][0]);
            printf ("Massa Vazia (kg): %f", foguetes[iF][1]);
        break;

        case 5:
            printf ("\n\nMassa total dos motores: "); // Engines total mass
            scanf (" %f", &mMotor);
            fflush (stdin);

            printf ("\n\nEficiência dos motores(Isp): "); // Engine efficiency (Isp)
            scanf (" %f", &ispMotor);
            fflush (stdin);
        break;

        case 6:
            printf ("\n\nPara qual foquete você quer calcular o dV? "); // Which rocket's deltaV shall be calculated?
            scanf (" %f", &qF);

            dV = (ispMotor * 9.80665 * log((foguetes[qF][1] + mMotor)/(foguetes[qF][2] + mMotor)));

            printf ("dV = %f", &dV);
        break;

        default:
            printf("\nOpção inválida. Por favor escolha um ação de 1-6 ou 0 para finalizar o programa.\n"); // Invalid option. Please choose an action between 1-6 or 0 to end the process

        }
    } while(escolha > 0);

    return(0);

    exit;
}

edit 3:

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <locale.h>

int main (void) {

setlocale(LC_ALL,"Portuguese");

int QntSubs, escolha, mF, eF, iF, ispMotor, qF, contagem, i, x; //mudarfoguete, excluir foguete, informaçao do foguete, massa do motor, qual foguete

float foguetes[1000][2], dV, mCheia, mVazia, mMotor;

do {

    printf ("\n1-Cadastrar os dados de um foguete"); // enter rocket values (dry and wet masses)
    printf ("\n2-Mudar os dados de um foguete já inserido"); // change rocket values (dry and wet masses)
    printf ("\n3-Excluir os dados de um foguete já inserido"); // delete rocket values (dry and wet masses)
    printf ("\n4-Listar os foguetes já cadastrados"); // list registered rockets (dry and wet masses)
    printf ("\n5-Incluir dados do motor substituto"); // enter substitute engine values (Total mass and Isp)
    printf ("\n6-Realizar cálculo de dV\n\n"); // calculate deltaV

    scanf ("%d", &escolha);
    fflush (stdin);

    switch(escolha) {

        case 1:
            printf ("\nQuantos foguetes serão cadastrados?: "); // how many rockets do you want to register?
            scanf (" %d", &x);

            for (contagem=0; contagem <x; contagem ++) {

                printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
                scanf (" %f", &mCheia);

                printf ("Massa do estagio vazio(kg): "); // dry Mass
                scanf (" %f", &mVazia);

                foguetes[contagem][0] = mCheia;

                foguetes[contagem][1] = mVazia;
            }
        break;

        case 2:
            printf ("\n\nMassa do estagio cheio(kg): "); // Wet Mass
            scanf (" %f", &mCheia);

            printf ("\nMassa do estagio vazio(kg): "); // Dry Mass
            scanf (" %f", &mVazia);

            printf ("\n\nQual foguete você deseja mudar?:"); // Which rocket shall be changed?
            scanf (" %d", &mF);

            foguetes[mF][0] = mCheia;
            foguetes[mF][1] = mVazia;
        break;

        case 3:
             printf ("\n\nQual é o número do foguete que você deseja excluir?: "); // Which rocket shall be deleted?
             scanf (" %d", &eF);

             foguetes[eF][0] = 0;
             foguetes[eF][1] = 0;
        break;

        case 4:
            printf ("\n\nQual foguete você deseja ver as informações?: "); // Which rocket's values shall be showed?
            scanf (" %d", &iF);

            printf ("Massa Cheia (kg): %f", foguetes[iF][0]);
            printf ("Massa Vazia (kg): %f", foguetes[iF][1]);
        break;

        case 5:
            printf ("\n\nMassa total dos motores: "); // Engines total mass
            scanf (" %f", &mMotor);

            printf ("\n\nEficiência dos motores(Isp): "); // Engine efficiency (Isp)
            scanf (" %f", &ispMotor);
        break;

        case 6:
            printf ("\n\nPara qual foquete você quer calcular o dV? "); // Which rocket's deltaV shall be calculated?
            scanf (" %d", &qF);

            dV = (ispMotor * 9.80665 * log((foguetes[qF][0] + mMotor)/(foguetes[qF][1] + mMotor)));

            printf ("dV = %f", &dV);

        break;

        default:
            printf("\nOpção inválida. Por favor escolha um ação de 1-6 ou 0 para finalizar o programa.\n"); // Invalid option. Please choose an action between 1-6 or 0 to end the process
        }

    } while(escolha > 0);

    return(0);

    exit;
}
arrays
c
multidimensional-array
asked on Stack Overflow Aug 28, 2020 by gguizzz • edited Sep 7, 2020 by marc_s

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0