私は C でプログラミングを学び続けていますが、今日、ある問題に遭遇しました。私のプログラムでは、ユーザーは時間の値を分単位で入力する必要があり、私のプログラムはそれを秒単位で計算します(実際には非常に単純です)。しかし、私はルールを設定したいと思います。時間はマイナスにはならないということです。だから私はこのコードを使用しました:
if(a<=0)
{
printf("Time cannot be equal to, or smaller than zero, so the program will now terminate\n");
exit(EXIT_FAILURE);
}
しかし今、私は自分のプログラムを終了したくありません。ユーザーが値を入力しなければならない状態に戻りたいのです。
プログラムの終了に問題がありましたが、いくつかの検索は役に立ちましたが、プログラムを再起動する方法を検索しても結果は得られませんでした。
これは私のプログラムのテキストです(私はLinuxで作業しています):
#include<stdio.h>
#include<stdlib.h>
main()
{
float a;
printf("\E[36m");
printf("This program will convert minutes to seconds");
getchar();
printf("Now enter your time in minutes(e.g. 5):");
scanf("%f", &a);
printf("As soon as you will press the Enter button you`ll get your time in seconds\n");
getchar();
getchar();
if(a<=0)
{
printf("Time cannot be equal to, or smaller than zero, so the program will now terminate\n");
printf("\E[0m");
exit(EXIT_FAILURE);
}
else
{
float b;
b=a*60;
printf("\E[36m");
printf("The result is %f seconds\n", b);
printf("Press Enter to finish\n");
getchar();
}
printf("\E[0m");
}
PS私はこの関数に正しく名前を付ける方法がわからないので、私はそれを再起動と呼んでいます。おそらく別の名前を持っていますか?