my outputs are not place where i want them to be

I am creating a monthly net income budget calculator, but when I enter some outputs, my program doesn't run the way I was expected. For some reason, my monthly net income part doesn't show how it doesn't perform the calculations instead just enter the number that I want to be in the expenses part. Please, could you tell me where I am wrong?

Last edited on
It looks like monthly_net is a value that the program is calculating, but there's currently a cin statement which prompts the user for entry. It seems like you could remove the cin statements if I understand correctly what you intend to do. (Check this also for left_income at the end of the program).

1
2
3
4
5
monthly_net= ((net_income*pay_frequency)/12);
if  (pay_frequency == 26 )
{
cout<<"your monthly net income is: ";
cin>> monthly_net;


You don't appear to need all the if and else if statements for printing out the monthly_net value. The cout statement in all cases is the same.

Edit: If you want to validate that they've entered one of a specific set of values for pay_frequency, you'd probably want to do it as soon as they enter the number and give them the opportunity to cin a number again before you do the calculation.


The numbers array only has 10 elements, so the valid indices for the array start at 0 and go to 9. 19 is going to be out of range.
1
2
for(int i=0;i<19;i++) 
cout<<numbers[i]<<","<<" "; 


cout<<numbers[19]<<endl;
Last edited on
To add some flexibility to the code, you could make the number of expenses a constant value and use that variable instead of hardcoding one particular number throughout the code. That way if you want to change the number of expenses to be entered, you only need to change it in one spot.

I made a couple of tweaks to the input/output of expenses. I'm sure others might have more suggestions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    const int numExpenses {10}; // constant value for number of expenses
    int numbers[numExpenses];
    int totalExpenses = 0;

    std::cout << "\nEnter " << numExpenses << " items from home expenses:";
    std::cout << "\nThe expenses are: ";
    for(int i = 0; i < numExpenses; i++){
        std::cin >> numbers[i];
        totalExpenses += numbers[i]; // increment the running total with the latest expense entered
    }
    
    std::cout <<"\nThe total monthly expenses are:\n";
    for (int i = 0; i < numExpenses; i += 1)
    {
        std::cout << numbers[i];
        if (i < numExpenses - 1)  // if we're not at the last expense, output a '+'
            std::cout << " + ";
    }
    std::cout << " = " << totalExpenses << std::endl;
Last edited on
yes i did a lot a careless mistakes thank you!
Topic archived. No new replies allowed.