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

Create a program that ask the user to enter his/her % of expenses for the follow

ID: 3542046 • Letter: C

Question

Create a program that ask the user to enter his/her % of expenses for the following categories: FOOD, GAS, CELLPHONE, CLOTHES and PARTY. In order to the expenses be balance all must sum 100%. Once the expenses are balance, the program must determine which category is the most expensive one. If there are 2 or more categories with the same percent, the program must tell the user which one they are.

Example 1:

FOOD PERCENT:  10

GAS PERCENT: 10

CELLPHONE PERCENT: 5

CLOTHES PERCENT: 20

PARTY PERCENT: 30

cout<< these expenses are not balanced. (They all must sum 100%)

--------------------------------------------------------------------------------------------------------------------

Example 2:

FOOD PERCENT:  20

GAS PERCENT: 10

CELLPHONE PERCENT: 20

CLOTHES PERCENT: 20

PARTY PERCENT: 30

cout<< these expenses are well balanced. ( The highest expense: party)

--------------------------------------------------------------------------------------------------------------------

Example 3:

FOOD PERCENT:  20

GAS PERCENT: 10

CELLPHONE PERCENT: 10

CLOTHES PERCENT: 30

PARTY PERCENT: 30

cout<< these expenses are well balanced. ( The highest expense: clothes, party)

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
string array[] = {"FOOD", "FOOD","CELLPHONE","CLOTHES","PARTY"};
int a[5];
int sum =0;
for(int i=0; i<5; i++)
{
cout << array[i] << " PERCENT: ";
cin >> a[i];
cout <<endl;
sum = sum+a[i];
}
if(sum!=100)
cout<<"these expenses are not balanced. (They all must sum 100%) " <<endl;
else
{
int max_index = 0;
for(int i=0; i<5;i++)
{
if(a[i] > a[max_index]) max_index = i;
}
int max_value = a[max_index];
string expense;
cout<<"these expenses are well balanced. ( The highest expense: ";
for(int i=0;i<5; i++)
{
if(max_value ==a[i])
expense+=array[i]+",";
}
expense = expense.erase(expense.length()-1);
cout << expense;
cout << " ) " << endl;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote