Answers
Code
Using for loop
#include<iostream>
using namespace std;
int main()
{
int i, amount=0;
//using for loop
for (int i = 1; i <= 21; i++)
{
amount += (i * 10);
}
cout << "Using for loop" << endl;
cout << "Dylan's account at the end of the 21 year: $" << amount << endl;
system("pause");
return 0;
}
output
using while loop
#include<iostream>
using namespace std;
int main()
{
int i, amount = 0;
//using while loop
i = 1; amount = 0;
while (i <= 21)
{
amount += (i * 10);
i++;
}
cout << "\n\nUsing while loop" << endl;
cout << "Dylan's account at the end of the 21 year: $" << amount << endl;
system("pause");
return 0;
}
using fo while
#include<iostream>
using namespace std;
int main()
{
int i, amount = 0;
i = 1; amount = 0;
//using do while
do
{
amount += (i * 10);
i++;
} while (i <= 21);
cout << "\n\nUsing do while loop" << endl;
cout << "Dylan's account at the end of the 21 year: $" << amount << endl;
system("pause");
return 0;
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.