fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct drone_t{
  5. char name[30];
  6. float top_s;
  7. float acceleration;
  8. };
  9.  
  10. size_t drone_creation(struct drone_t var[], size_t n);
  11. void drone_calc(struct drone_t var[], size_t n);
  12.  
  13. #define MAX_DRONE 10
  14. enum { NONE, CREATE, CALCULATE, EXIT };
  15.  
  16. int main(void){
  17. struct drone_t variables[MAX_DRONE];
  18. int n = 0;
  19. int selection;
  20.  
  21. do {
  22. selection = NONE;
  23. "Welcome to the drone travel time calculator\n"
  24. "1. Create Drone\n"
  25. "2. Calculate Time\n"
  26. "3. Exit\n"
  27. );
  28. scanf("%d", &selection);
  29. switch(selection){
  30. case CREATE:
  31. n = drone_creation(variables, MAX_DRONE);break;
  32. case CALCULATE:
  33. drone_calc(variables, n);break;
  34. case EXIT:
  35. puts("See ya!");
  36. break;
  37. default:
  38. puts("Invalid input!");
  39. while(getchar()!='\n');
  40. }
  41. } while(selection != EXIT);
  42. }
  43.  
  44. size_t drone_creation(struct drone_t var[], size_t n){
  45. size_t i;
  46. for(i = 0; i < n; ++i){
  47. printf("Please enter the name of the drone(Period(.) means end of input): ");
  48. scanf("%29s", var[i].name);
  49. if(var[i].name[0] == '.' && var[i].name[1] == '\0')
  50. break;
  51. printf("Please enter the Top Speed of the drone: ");
  52. scanf("%f", &var[i].top_s);
  53. printf("Please enter the acceleration of the drone: ");
  54. scanf("%f", &var[i].acceleration);
  55. }
  56. #if DEBUG
  57. for(size_t k = 0; k < i; ++k){
  58. printf("DEBUG>name:%s, top speed:%.2f acceleration:%.2f\n",
  59. var[k].name, var[k].top_s, var[k].acceleration);
  60. }
  61. #endif
  62. return i;
  63. }
  64. void drone_calc(struct drone_t var[], size_t n){
  65. ;//not yet
  66. }
  67.  
Success #stdin #stdout 0s 10320KB
stdin
1
Inspire-2
108
20
.
3
stdout
Welcome to the drone travel time calculator
1. Create Drone
2. Calculate Time
3. Exit
Please enter the name of the drone(Period(.) means end of input): Please enter the Top Speed of the drone: Please enter the acceleration of the drone: Please enter the name of the drone(Period(.) means end of input): Welcome to the drone travel time calculator
1. Create Drone
2. Calculate Time
3. Exit
See ya!