母集団と変化が割り当ての結果のように見えるのに問題があります。 何が間違っているのか完全にはわかりません。 どんな助けでも大歓迎です。
割り当て、私のコード、および私のコードの結果のスクリーンショット。
行で:
$change = $newpop - $pop;
とは $ポップ? あなたはそれが何を持っているかを示しません。 あっ、待って; 表示するものは何もないかもしれません $ポップ 問題です。
コードを見てください。 何が起こるかをシミュレートします。 コードは計算します $newpop から $curpop. 次回はどうなりますか? 計算する $newpop から $curpop また。 値は何ですか $curpop 二回目?
また、よくわかりませんが、整数を浮動小数点数に変換して、浮動小数点数の結果で乗算 (および/または除算) を行う必要がある場合があります。 私はPHPの経験が十分ではなく、確実に知ることができません。
これらの 2 つまたは 3 つの問題を修正すれば、コードは機能するはずです。 私はそれをテストしましたが、これは宿題なので、コードを与えるべきではありません。
別の問題があります。 あなたのコードは、2020 年の人口が 1,080 人であることを示していると思います。 印刷する 計算の前に、新しい人口の代わりに現在の人口を出力します。 PHPについてはわかりませんが、おそらく初期化する必要があります 両替 0に。
提案があります。 最初に変更を計算し (実行できます)、現在の人口に変更を追加して、新しい人口を取得します。
1 いいね
-
ループごとではなく、成長率を 1 回計算します。 1 のすぐ北の数値である必要があります。変化しません。 その後、現在の人口に成長率を掛けることができます。 (X + X(Y/Z) は X で因数分解できます)
-
印刷と計算を反転する場合は、変更を初期化する必要があります。 それ以外の場合は、呼び出された時点で未定義です。
-
PHP は int から float への変換を処理しますが、2022 年から人数の端数が必要でない限り、後で整数に丸める必要があります。
-
あなたの宿題、フォーマット、その他すべてを、簡単な Google 検索で何度も Chegg で見つけました。 学生はオンラインで答えを得ているので、課題の再利用をやめるよう教授に伝えてください。 次に、検索エンジンのアルゴリズムにフィードします。
Transcribed image text: Overview: Write a program to project several years of population growth. The user should be able to enter in the number of years, the current population, and the growth rate. Your output screen should print out the numbers the user entered, as well as the results in a table. Style the table as shown below (though exact colors don't have to match). Include a link back to the input form. Format the numbers in your output. Input Form: Fileme Available Actions 61 Delta Opel Open Here 05-put 05- ci per Last Updated May 05 2020 10:07:31 May 03 2020 10:07:31 May 03 2020 10:07:31 Delete Bursa wa Mare Delete Vw Bora wscas -New File hw05 - Population Growth Years to forecast: 10 Current Population: 10000 Growth Rate: 8 Calculatel Output: Filename Last Updated Available Acties s-resultsple bw03-input html May 05 2020 10:11:13 May 03 2020 10 08 45 May 03 2020 10:07:31 Delete Voce Delale Open Here Delete Vw Sensor Med Delet View hrs.css New File Output: Filename Last Updated Available Actions Delete View Source Open In New Tab Open Here Delete View Source Open In New Tab Open Here hw0S-results.phpMay 0S 2020 10:11:13. hwos-input html May 05 2020 10:08:45 hwo5.css May 05 2020 10:07:31 -New File DeleteView Source hw05 - Population Growth Starting population : 1,000 Growth rate: 8.0 To perform another calculation click here. Year Population Change 2020 1,080 80 2021 1,166 86 2022 1,260 93 2023 1,360 101 2024 1,469 109 2025 1,587 118 2026 1,714 127
1 いいね