Да, это C, но C приглашает Undefined Behavior из-за неудачной проверки ввода пользователя. Что происходит в вашем коде, если пользователь вводит 'r'
вместо '5'
при вводе высоты мяча?
Чтобы предотвратить неправильный ввод и восстановить его, необходимо проверить возврат вашей функции ввода и очищают stdin
любых оскорбительных символов перед вашей следующей попыткой чтения, например
/* validate every input */
if (scanf ("%lf", &startingHeight) != 1) {
int c;
fputs ("error: invalid input.\n", stderr);
do /* read offending chars until '\n' or EOF */
c = getchar();
while (c != '\n' && c != EOF);
continue;
}
Несмотря на то, что с do .... while (...)
вы просто перепрыгиваете до конца цикла и ваш startingHeight < 0
тест ложен, и вы переходите к вопросу о скорости, лучше:
for (;;) { /* loop continually until valid input */
printf ("\n Enter initial height of the ball (in ft.): ");
/* validate every input */
if (scanf ("%lf", &startingHeight) != 1) {
int c;
fputs ("error: invalid input.\n", stderr);
do /* read offending chars until '\n' or EOF */
c = getchar();
while (c != '\n' && c != EOF);
continue;
}
if (startingHeight < 0) {
printf ("\t The initial height must be greater than or equal to 0");
/* you should empty stdin here as well -- hint: create a function */
}
else
break;
}
то, как вы переспрашиваете вопрос о высоте, пока у вас не будет действительного startingHeight >= 0
.
Другой нит, не используйте printf
для вывода односимвольного символа, то есть для чего putchar
или fputc
, например,
// printf ("\n"); /* replace this with... */
putchar ('\n');
Кроме того, нет необходимости в двух- printf
вызовах (вы не выполняете никаких преобразований), когда будет делать один puts
, например
// printf("\n");
// printf("Time\tHeight\n");
puts ("\nTime\tHeight");
В остальном, кроме обычного начала неудачных проверок, у вас все хорошо.
You just build the applications in Visual Studio, and run them under Mono instead of under .NET. The binaries should be compatible... but you'll need to make sure you don't use any libraries which aren't available in Mono - see the Mono Application Compatibility Guidelines.
(According to that page, you need to turn off incremental builds in Visual Studio though - a point I wasn't aware of before :)
Miguel has posted this entry a while ago, so it's quite dated. You can also try this and this (all hail Web Archive!)
See this article on how to run your apps while targeting the mono framework from VS.
Начиная с версии 2.0 MonoDevelop поддерживает формат файла проекта / решения VisualStudio. Это означает, что вы можете использовать одну и ту же кодовую базу в Windows с VS и .Net и в Linux с MonoDevelop и Mono. Это, на мой взгляд, лучший способ сделать это. Нет никаких серьезных причин для запуска приложения в Mono в Windows, кроме как для целей тестирования и для этого я бы предпочел настроить виртуальную машину для тестирования программного обеспечения в собственной среде.