fork download
  1. // C code
  2. // This program will input and store meteorological data into an array.
  3. // Developer: Faculty CMIS102
  4. // Date: Jan 31, 2014
  5. #include <stdio.h>
  6. int main ()
  7. {
  8. /* variable definition: */
  9. float Raindata[60], WindData[60];
  10. float Rain=1.0, WindSpeed=1.0;
  11. int count=0,i;
  12.  
  13. // Input Data
  14. while (Rain > 0)
  15. {
  16. printf("Enter rain and windspeed\n");
  17. scanf("%f,%f",&Rain,&WindSpeed);
  18. // Only assign if positive
  19. if (Rain > 0) {
  20. Raindata[count]=Rain;
  21. WindData[count]=WindSpeed;
  22. count= count + 1;
  23. }
  24. }
  25.  
  26. // Print data
  27. for (i=0; i<count;i++)
  28. printf ("Data element %d is %f and %f\n", i,Raindata[i],WindData[i]);
  29.  
  30. return 0;
  31. }
  32.  
  33.  
Success #stdin #stdout 0s 4528KB
stdin
2,3
3,2
6,7
-1
stdout
Enter rain and windspeed
Enter rain and windspeed
Enter rain and windspeed
Enter rain and windspeed
Data element 0 is 2.000000 and 3.000000
Data element 1 is 3.000000 and 2.000000
Data element 2 is 6.000000 and 7.000000