Here is the program that I have to make:

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 fin ishes, the program should display the amount that the user is over or under budget.

This is what I have so far:

#include<iostream>
using namespace::std;

int main ()
{
int limit = 3000;
double monthly = 0, 
budget,olimit,ulimit;

do{

cout<<"How much did you spend today? ";
cin>>budget;

if(budget < limit)
{
    ulimit = limit - budget;
    cout<<"You are below your maximum budget. ";
}
    
if(budget > limit)
{
    olimit = budget - limit;
    cout<<"You went over your limit in your budget. ";
}

monthly += budget;

}while (monthly <= 12);

return 0;
}

Can I get any help please? Thank you in advance :)

Sorry, I didn't give enough details. I just want to know how it can keep adding up until it reaches the maximum budget after a period of time because when I run it, after the first submission of budget, it says that it is under the limit and doesn't keep the loop running.

You gave enough information for me to understand at first.

The error seems to have some thing to do with your double declaration.

Maybe try this code and tell me what goes:

#include <iostream>
using namespace std;
void over()
{
     system("CLS");
     cout << "You went over your budget limit.\n";
     system("PAUSE");
 }

int main()
{
bool firsttime = true; // To detect if it's your first input or not.
int limit = 3000; // Limit of what you can use.
int budget = 0; // The amount retrieved from what you enter against your limit.
repeatagain: // Goto.
if(firsttime == true) // Test whether or not it's the first input.
{
cout << "Your max limit is $3,000.\n" << "\nEnter first expense cost.\n";
}
else {cout << "Your max limit is $3,000.\n" << "\nEnter next expense(s).\n";} // Show a different display if not the first input.
do
{
cin >> budget; // Retrieve the user's budget.
if(limit > 0) // Test to see whether or not the limit has been retrieved from the budget you're using against it.
{
limit -= budget; // Take the value entered from the budget and reduce it from the limit.
budget = 0; // Return the value of 0 back to the budget for the next input.
system("CLS"); // Clear the screen to redraw.
firsttime = false; // Set first input boolean to false because you already entered your first input.
if(limit > 0) // Test again if the limit still has more value.
{
goto repeatagain; // Go again to repeat the do while loop.
}
else if(limit < 0) // Test if the limit has been exceeded.
{
     over(); // Call to the function over to let the user know they exceeded the limit.
 }
}
} while(budget == 0 && limit > 0); // The loop while keep going as long as the limit is larger than 0 and the budget is equal to 0.
return 0;
}

Perhaps you should just use two integers or doubles with just one name and value? The one I made worked for me myself and it's just two simple integers.

PS: I am very crappy at programming, so if the code doesn't work don't blame me too much.

I also want you to know that a lot of people on this site are annoying and want you to explain every detail of a problem whereas I can understand simple and short explanations.
Check my code to understand exactly how it's done. I can give more info if needed.

Edited 5 Years Ago by spoonlicker: n/a

Sorry, I didn't give enough details.

That's correct. Presently you're using monthly to accumulate the expenditures, which in this case will cause the loop to stop after the value exceeds 12. Try writing this program under the assumption that it only manages a single month, that should make the problem simpler.

This question has already been answered. Start a new discussion instead.