Note that there are some explanatory texts on larger screens.

plurals
  1. POBug with quantity of float numbers on C
    primarykey
    data
    text
    <p>Well, first of all, I'm nothing close to versed on C, so this might have a simple answer, but I can't figure out what it could be. Moreover, my English is not what you'd call perfect, so I apologize in advance if I make myself hard to understand.</p> <p>I'm trying to do this little program that would let me do simple calculations for travel time with fixed speeds, where all I'd have to input is the distance to travel. I started to code it, and soon enough I got a semi-functional console program, but then it started to grow and grow, and then came a point where I seemingly can't add any more float numbers to the code. Here's the code so far:</p> <pre><code>#include&lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;math.h&gt; /* TENGO QUE ARREGLAR ESTO, ME CAUSA BRONCA CON EL NÚMERO TOTAL DE FLOAT NUMBERS*/ main() { float x1, km, mn, mn1, mn1a, mn1b, mn1c, mn2, mn2a, mn2b, mn2c, mn3, mn3a, mn3b, mn3c, mn4; int c=1; printf("\n\n\tTiempo de recorrido\n\n"); if (x1 &gt;= 0) { do { printf("\tEscribe distancia en mapa: "); scanf("%f", &amp;x1); c = x1; km = x1*50; // Distancia real mn = km; mn1 = mn/5; // Tiempo de viaje mn1a = mn1/18; // Jornadas de marcha mn1b = mn1 + (floorf(mn1a)*6); // Tiempo total del viaje mn1c = mn1b/24; // Días totales de viaje mn2 = mn/8;// Tiempo de viaje mn2a = mn2/18; // Jornadas de marcha mn2b = mn2 + (floorf(mn2a)*6); // Tiempo total del viaje mn2c = mn2b/24; // Dias totales de viaje mn3 = mn/25;// Tiempo de viaje mn3a = mn3/18; //Instrucciones PRINT printf("\n\n\tNumero de kilometros = %3.2f km", km); if (mn1 &lt; 24){ printf("\n\n\tTiempo a 5 km/h (caminata) = %3.2f horas", mn1); } else{ printf("\n\n\tViaje en caminata (5 km/h)\n"); printf("\n\tTiempo de recorrido = %3.2f horas", mn1); printf("\n\tJornadas de marcha = %3.2f jornadas", mn1a); printf("\n\tTiempo total = %3.2f horas", mn1b); printf("\n\tDias totales = %3.2f dias\n", mn1c);} if (mn2 &lt; 24){ printf("\n\tTiempo a 8 km/h (a caballo) = %3.2f horas", mn2);} else{ printf("\n\n\tViaje a caballo (8 km/h)\n"); printf("\n\tTiempo de viaje = %3.2f horas", mn2); printf("\n\tJornadas de marcha = %3.2f dias", mn2a); printf("\n\tTiempo total = %3.2f horas", mn2b); printf("\n\tDias totales = %3.2f dias\n", mn2c); } if (mn3 &lt; 24){ printf("\n\tTiempo a 25 km/h = %3.2f horas\n", mn3); } else{ printf("\n\n\tTrote de caballo (25 km/h)\n"); printf("\n\tTiempo de viaje = %3.2f horas", mn3); printf("\n\tJornadas de marcha = %&amp;.2f días", mn3a); printf("\n\tJornadas de marcha = %3.2f horas", mn3); } } while (c &gt;= 0); } else{ getch(); } } </code></pre> <p>Now, when I try to run the code as it is above, there's no problem with the output. But, when I try to add another variable declaration below (with mn4 which is already added on the float declaration), the program bugs out: I only get the text "Escribe la distancia en el mapa" (without the : symbol"), and when I type any key, it sends the message "Process exited with return value 49/50", and it closes after the next keystroke.</p> <p>I've tried thinkering with the code in any way I can think of, but nothing worked, except that it changed the return values between 49 and 50, for some reason. I hope someone could tell me how to fix this, or, if that's not possible, to tell me why it's so, so I can find a way around that.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload