Budget Analysis Write a program that asks the user to enter the amount that he o
ID: 3599938 • Letter: B
Question
Budget Analysis
Write a program that asks the user to enter the amount that he or she has budgeted
for a month. A loop should then prompt the user to enter each of his or her expenses
for the month and keep a running total. When the loop finishes, the program should
display the amount that the user is over or under budget.
Explanation / Answer
C++ program to do this -
#include<iostream>
using namespace std ;
int main()
{
float a , ch=1 , b , c=0;
cout<<"Enter your budget for the month : ";
cin >> a;
cout<<endl;
while(ch)
{
cout <<"Enter an expense amount , or a negative number to quit :" ;
cin >> b ;
if(b>=0)
{
c=c+b;
}
else
if(b<0)
{
ch=0;
}
}
if(c>a)
{
cout<<"You are over budget by $"<<c-a<<endl;
}
else
if(a>c)
{
cout<<"You are lower budget by $"<<a-c<<endl;
}
else
{
cout<<"You spent the budget amount exactly"<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.