Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// This program shows how the toupper and tolower functions can be // applied in

ID: 3546995 • Letter: #

Question


// This program shows how the toupper and tolower functions can be
// applied in a C++ program

#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;

int main()
{
    int week, total, dollars;
    float average;
    char choice;

    cout << showpoint << fixed << setprecision(2);

    do
    {
        total = 0;
        for(week = 1;week <= 4;week++)
        {
            cout << "How much (to the nearest dollar) did you"
                 <<" spend on food during week " << week << " ?:" << endl;
            cin >> dollars;

            total = total + dollars;
        }
        average = total / 4.0;

        cout << "Your weekly food bill over the chosen month is $"
             << average << endl << endl;
        do
        {
           cout << "Would you like to find the average for another month?";
           cout << endl << "Enter Y or N" << endl;
           cin >> choice;
        } while(toupper(choice) != 'Y' && toupper(choice) != 'N');

    } while (toupper(choice) == 'Y');
    
    
    return 0;
}




Bring in case_convert.cpp from the Lab 10 folder. Note that this is Sample Program 10.2. Exercise 1: Run the program several times with various inputs. Exercise 2: Notice the following do-while loop which appears near the end of the program: do { cout

Explanation / Answer

//The toupper and tolower funyctions are used for input verification. Only the character 'y' or 'n' are accepted as correct input. //casing to upper or lower case helps lets it recongnize y Y, n and N as accepable choices.



// This program shows how the toupper and tolower functions can be
// applied in a C++ program

#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;

int main()
{
int week, total, dollars;
float average;
char choice;

cout << showpoint << fixed << setprecision(2);

do
{
total = 0;
for(week = 1;week <= 4;week++)
{
cout << "How much (to the nearest dollar) did you"
<<" spend on food during week " << week << " ?:" << endl;
cin >> dollars;

total = total + dollars;
}
average = total / 4.0;

cout << "Your weekly food bill over the chosen month is $"
<< average << endl << endl;
do
{
cout << "Would you like to find the average for another month?";
cout << endl << "Enter Y or N" << endl;
cin >> choice;
} while(tolower(choice) != 'y' && tolower(choice) != 'n');

} while (tolower(choice) == 'y');


return 0;
}