指数関数を作成しようとしていますが、期待どおりに動作しないようです。基本的なことを理解していない場合は申し訳ありません。インターネットから少しずつ学んでいるだけです。
float x;
float y;
float z;
int h;
int j;
float exponent (float a, float b)
{
float r;
while(b > 1)
{
r = a * a;
b = b - 1;
}
return (r);
}
^変数を含む関数のスニペット。
cout << "EXPONENT MODE\n\n";
cout << "Please enter a number: ";
cin >> x; system("CLS");
cout << "Please enter another number as the exponent for the first: ";
cin >> y;
z = exponent(x, y);
cout << "Calculating the answer, please wait";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << ".";
Sleep(1000);
cout << "\n\nYour answer is : ";
cout << r;
Sleep(5000);
system("CLS");
cout << "Would you like to calculate another set of numbers? (yes = 1, no = 2) : ";
cin >> h;
system("CLS");
^コンソールで実行したい部分(コードだけ)
基本的に、ユーザーに 2 つの数値を入力してもらいます。最初の (x) は基数、2 番目の (y) は指数です。プログラムは x を a として、y を b として入力し、関数を実行する必要があります。何が起こったか: 入力 1: 5、入力 2: 3、予期: 125、受信: 25。while を (b > 0) に変更することを考えています。あなたたちがそれを助けることができれば、それは素晴らしいことです!. system("CLS")
(また、コードで私を判断しないでください)