gpt4 book ai didi

c++ - 循环显示一个数字增加 0.2% 5 次

转载 作者:行者123 更新时间:2023-11-28 01:52:51 25 4
gpt4 key购买 nike

<分区>

我很难弄明白这一点。我需要创建一个循环来重复 5 次。此循环需要取整数 x 并将其乘以 .2 并显示结果。然后需要将该结果乘以 .2 并显示结果。它需要执行 5 次。

float credithours;
float tuition = 274.41;


cout << "How many credit hours are you taking this semester? " << endl;
cin >> credithours;
cout << "Your current semester tuition is " << credithours * tuition << endl;

float tuitionfive = credithours * tuition * 2;

cout << "Your tuition for the year is " << tuitionfive << endl;

float tuitiontotal = (tuitionfive * .2) + (tuitionfive);


for (float x = 1; x <= 5; x++) {
x = tuitiontotal * .2 + tuitionfive;
cout << x << endl;
}

编辑*****

我在此处帮助后修复了代码,这是最终结果:

float credithours;
float tuition = 274.41;



cout << "How many credit hours are you taking this semester? " << endl;
cin >> credithours;

float semestertuition = credithours * tuition;

cout << "Your current semester tuition is " << semestertuition << endl;

float tuitionfive = semestertuition * 2;

cout << "Your tuition for the year is " << tuitionfive << endl;

cout << "Your tuition for the next 5 years is: " << endl;

for (int i = 0; i < 5; ++i)
{
tuitionfive = tuitionfive * .2 + tuitionfive;
cout << tuitionfive << endl;
}

我还没有使用指数,因为我需要做更多的研究才能更多地了解它。再次感谢您的帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com