SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: amedinadiaz en Lunes 17 de Noviembre de 2003, 18:48

Título: Re: SOCORRO AYUDA URGENTE CON UN PROGRAMA DE MEDICION DE TEM
Publicado por: amedinadiaz en Lunes 17 de Noviembre de 2003, 18:48
Me piden que haga un programa que al introducirle una serie de temperaturas, las que sean, (scanf), me diga cuantas veces he introducido esa temperatura mediante la siguiente tabla:

Datos introducidos: 0, 0, 1, 2, 3, ,3

- 0 grados 2 veces
- 1 grados 1 veces
- 2 grados 1 veces
- 3 grados 2 veces
.
.
.
-40 grados x veces

Asi hasta 40. Pero el problema es q tengo q acerlo usando arrays. Lo q llevo asta aora os lo pongo aki, ahi sale todo emjor explicado aunque esta en ingles:(tambien estan hechas las 2 primeras partes del programa que me pedian hallar cuantas veces era superior a 30C y cuantas igual a 19C)

#include <stdio.h>

int main (void)

{
   /* Declaring the integers */
   int temp[41];
   int input=0, T=0, n, m;
    int day=0, day2=0, C=0, day3=0;

   printf("Temperature Readings Program.n");
   printf("By Antonio Medina.n");
   printf("MS-DOS Version 1.0n");
   printf("-----------------------------n");
   printf("n");
   printf("Enter temperature readings:n");
   
   while(T!=-999) // Declaring the while loop, as long as Temperature is not -999 it works.
      
   {   
      scanf("%d", &T);
       if((T<0)&&(T>-999))// If the value is negative this 'if' will set it to 0.
      {
          printf("Your value has been set to 0n");
         T=0;
      }
       else if(T>40)// If the value is bigger than 40, this 'if' will set it to 40.
      {
          printf("Your value has been set to 40n");
         T=40;
      }

      temp[input]=T;
      input+=1;
   }
   

    for(n=0; n<=input-2; n++)// With this 'for' loop we are calculating the times
   {
         if(temp[n]>30)
           day=day+1;

   }   
   
   printf("n");
    printf("***Days greater than 30C =%d***n", day);

    for(m=0; m<=input-2; m++)
   {
        if(temp[m]==19)
          day2=day2+1;

   }
   printf("n");
    printf("***Days equal to 19C =%d***n", day2);

    //HASTA AQUI ES DONDE LLEGO, MAS ABAJO SON SOLO INTENTOS MIOS.
   for(C=0; C<41; C++)
   {
      if(temp[input]=C)
         day3=day3+1;
      printf("%dC in %d daysn", C, day3);

   }
      
   
   return 0;
}
Título: Re: SOCORRO AYUDA URGENTE CON UN PROGRAMA DE MEDICION DE TEM
Publicado por: carmamezo en Lunes 17 de Noviembre de 2003, 22:58
Aqui tienes una posibilidad de como hacerlo:
#include <stdio.h>
#include<windows.h>

void main()
{
   int temp[41],aux,i,j,cont;

   for (i=0;i<41;i++)
   {
      system("Cls");   //borrar pantalla
      printf("Introduce Temperatura %d: ",i+1);
      scanf("%d", &aux);
      if(aux<0)
         aux=0;
      if(aux>40)
         aux=40;
      temp=aux;
   }
   cont=0;
   for(i=0;i<41;i++)
   {
      for(j=0;j<41;j++)
         if(temp[j]==i)
            cont++;
      printf("n%d grados %d veces",i,cont);
      cont=0;
   }
}

Espero que te sirva de ayuda, un saludo.
Título: SOCORRO AYUDA URGENTE CON UN PROGRAMA DE MEDICION DE TEMPERA
Publicado por: amedinadiaz en Martes 18 de Noviembre de 2003, 03:38
Muchas gracias, la verdad es que me has salvado el cuello porque este era un trabajo de la uni que me llevo comiendo el coco 5 dias y no encontraba la solucion. Muchas gracias en serio!