简体   繁体   中英

How can I solve these errors and warnings? Also a few questions from this program

I'm making a program that takes data from various rockets (except their first stage engines) and calculates dV with a new, substitute engine. Here is the code:

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

main () {

int choice;

do {

    printf ("\n1-Register rocket data");
    printf ("\n2-Change already registered data");
    printf ("\n3-Delete rocket data");
    printf ("\n4-Show registered rockets");
    printf ("\n5-Register substitute engine data");
    printf ("\n6-Calculate dV with substitute engine");
    printf ("\n0-End");

    scanf ("%d", &choice);

    switch(choice) {
        case 1:
            dV();
        break;

        case 2:
        break;

        case 3:
        break;

        case 4:
        break;

        case 5:
        break;

        case 6:
        break;

        }

    } while(choice != 0);

}


dV () {

    int count, x, i;
    float rockets[] , dV, wetMass, dryMass, Isp;

    printf ("How many rockets will be registered?");
    scanf ("%d", &x);

    while (i == 1) {

        for (count=1; count <= x; count++)


            printf ("\n\nWet Mass(kg): ");
            scanf ("%f", &wetMass);
            fflush (stdin);

            printf ("Dry Mass: ");
            scanf ("%f", &dryMass);
            fflush (stdin);

            printf ("Specific Impulse(Seconds): ");
            scanf ("%f", &Isp);
            fflush (stdin);

            printf ("\nType 1 to add a stage or 0 to end the process: ");
            scanf ("%d", &i);

            dV = (Isp * 9.8 * log(wetMass/dryMass) + dV);

            dV = rockets[x++];


            }

}

The error:

error: array size missing in 'rockets' (line 50)

Warnings:

warning: implicit declaration of function 'dV' [-Wimplicit-function-declaration} (line 22) warning: return type defaults to 'int' (Wimplicit-int) (line 47)

First question: How do I solve these errors and warnings?

Second question: How can I make a vector with user-defined number of elements? The user has to be able to register as many rockets as they want. My plan is to calculate the dV for each rocket and store it in an element of the rocket[] vector after the substitute engine data is provided.

Third question: How can I change the value of an already defined element in a vector?

Fourth question: How can I assign vector elements progressively? By that I mean: First registered rocket data should go to rockets[0], the second to rockets[1], etc.

edit: I forgot to add this after line 55

printf ("\ntype 1 to add a stage or 2 to end the process: ");
scanf ("%f", &i);

To remove errors and warnings, do changes as below ie create float array of rockets after you fetched value of x and initialize i by 1 before using it in while and add void in return type of dV function if any return value not needed.

void dV () {

    int count, x, i;
    float  dV, wetMass, dryMass, Isp;

    printf ("How many rockets will be registered?");
    scanf ("%d", &x);

    float rockets[x];

    i=1;

    while (i == 1) {
.
.
}

Answer to your second question: either make rockets as global array or return it to main through dV function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM