Convert do while to for loop

I was wondering how I could convert this section of my code to a for loop

1
2
3
4
5
6
7
8
9
10
do {
    cout << "Enter all of your expenses for the month: " << endl;
    cin >> monthlyE;
    sum += monthlyE;


    cout << "Would you like to enter more expenses? (Y/N)" << endl;
    cin >> ans;
    system("cls");
} while (ans == 'y' || ans == 'Y');
Last edited on
1
2
3
4
5
6
7
8
9
10
for (ans = 'y'; ans == 'y' || ans == 'Y';) {
    cout << "Enter all of your expenses for the month: " << endl;
    cin >> monthlyE;
    sum += monthlyE;


    cout << "Would you like to enter more expenses? (Y/N)" << endl;
    cin >> ans;
    system("cls");
}
Topic archived. No new replies allowed.