現在、3つのヴァイラブルを入力できるようにする関数を使用する必要があるアサイメントのプログラムを作成しています。私はこれらの変数を私の主な機能に戻すことができず、以前に尋ねられた他の同様の質問を見て、ポインタを使用しようとしましたが、それを動作させることができません。私の試みは以下の通りです:ポインタを使用してCの関数から複数の値を返す方法
#include <stdio.h>
#include <stdlib.h>
//Function Header for positive values function
double get_positive_value(double* topSpeed, double* year, double*
horsepower);
int main(void){
int reRunProgram = 0;
while (reRunProgram==0)
{
//variable declarations
double tS;
double yR;
double hP;
int menuOption;
int menuOption2;
//menu
printf("1.Create Bugatti\n");
printf("2.Display Bugatti\n");
printf("3.Exit\n");
//user choice
scanf("%d", &menuOption);
//Create car
if (menuOption == 1) {
//run the get positive values function
get_positive_value (&tS, &yR, &hP);
printf("top speed is %lf\n", tS);
}
//Display car (but no car created)
else if (menuOption == 2){
printf("error no car created\n");
}
//Exit
else if (menuOption ==3){
exit(EXIT_FAILURE);
}
}
return 0;
}
double get_positive_value(double* topSpeed, double* year, double*
horsepower)
{
do {
printf("Please enter the top speed of the bugatti in km/h\n");
scanf("%lf", &topSpeed);
} while(*topSpeed<=0);
do{
printf("Please enter the year of the bugatti, in four digit form (e.g. 1999)\n");
scanf("%lf", &year);
} while(*year<=0);
do{
printf("Please enter the horsepower of the bugatti\n");
scanf("%lf", &horsepower);
} while(*horsepower<=0);
}
CまたはC++?あなたはこの質問をC++とタグ付けしましたが、タイトルに「in C」と書いたのですか? – Rakete1111
タグを入力する際にエラーが発生していたことをお詫び申し上げます。これはCです(私は正しく編集されています) –
コードはコンパイルされません。 –