This is the code that I have and for some reason it is not given me that I need.

#include <iostream>
#include <iomanip>

using namespace std;
int main ()
{
    // variables
    double salary = 0.0;
    int RATE = .03;

    // enter salary
    cout << "Salary (-1 to stop): ";
    cin >> salary;

    // display raises with 2 decimal places
    cout << fixed << setprecision(2);

    //begin loop 
    while (salary != -1)
    {
        cout << "Annual Raises for next three years: " << endl;

        // while loop to calculate annual raises
        while (RATE < .07)
        {
            // display annual raise amount
            cout << RATE * 100 << "% raise: ";
            cout << salary * RATE << endl;

            // update salary value and annual raise rate.
            salary += (salary * RATE);
            RATE += .01;

            //enter salary

            cout << "Salary (-1 to stop): ";
            cin >> salary;

            // reset variables
            RATE = .03;

        } //end of loop
        return 0;
    }   // end of file
    }

I need to display the amount of annual raises for the next three years. All it is giving me is where the user can put in a salary and then nothing for the raise. It is not even letting me end the program by entering (-1). Please someone help me??????

Recommended Answers

All 11 Replies

I'm not entirely sure what you're trying to do, but I took a guess:

#include <iostream>
#include <iomanip>

using namespace std;
int main ()
{
    // variables
    double salary = 0.0;
    int RATE = .03; //Why is this an integer? Integers don't have decimals.

    // enter salary
    cout << "Salary (-1 to stop): ";
    cin >> salary;

    // display raises with 2 decimal places
    cout << fixed << setprecision(2);

    //begin loop 
    while (salary != -1)  
    {
        cout << "Annual Raises for next three years: " << endl;

        // while loop to calculate annual raises
        while (RATE < .07)
        {
            // display annual raise amount
            cout << RATE * 100 << "% raise: ";
            cout << salary * RATE << endl;

            // update salary value and annual raise rate.
            salary += (salary * RATE);
            RATE += .01;

            //enter salary  //Why?

            cout << "Salary (-1 to stop): "; //WHY????
            cin >> salary; //AAARRRRGGGGHHHH!!!!!

            // reset variables
            RATE = .03; //You've condemned us to loop here eternally!

        } //end of loop
        return 0;
    }   // end of file //No, it's not.
    }   // This is.

So I rewrote it to do what I GUESSED was what you wanted.
Disclaimer: No flamingos were harmed in the rewriting of this software.
Amended Disclaimer: Yet.

#include <iostream>
#include <iomanip>

using namespace std;
int main ()
{
    // variables
    double salary = 1.0; //Change so that
    double RATE = .03;


    // display raises with 2 decimal places
    cout << fixed << setprecision(2);

    //begin loop 
    while (salary > 0.0) //This is just cleaner with floating point numbers.
    {
        // enter salary
        cout << "Salary (negative number to stop): "; 
        cin >> salary;

        cout << "Annual Raises for next three years: " << endl;

        // while loop to calculate annual raises
        while (RATE < .06) //.07 would include a fourth year. Not sure you wanted that.
        {
            // display annual raise amount
            cout << RATE * 100 << "% raise: ";
            cout << salary * RATE << endl;

            // update salary value and annual raise rate.
            salary += (salary * RATE);
            RATE += .01;

        } //end of inner loop
    }   // end of outer loop
        return 0;
}   // end of file

I think I am in the right direction but it is not allowing me to say put two different salaries input. It also is not allowing me to stop the program by the (-1).

Can you post the code that you have now?

#include <iostream>
    #include <iomanip>

    using namespace std;
    int main ()
    {
        // variables
        double salary = 1.0;
        double RATE = .03;


        // display raises with 2 decimal places
        cout << fixed << setprecision(2);

        //begin loop 
        while (salary > 0.0) 
        {
            // enter salary
            cout << "Salary (negative number to stop): "; 
            cin >> salary;

            cout << "Annual Raises for next three years: " << endl;

            // while loop to calculate annual raises
             while (RATE < .06) 
             {
                // display annual raise amount
                cout << RATE * 100 << "% raise: ";
                cout << salary * RATE << endl;

                // update salary value and annual raise rate.
                salary += (salary * RATE);
                RATE += .01;

             } //end of inner loop
        }   // end of outer loop
            return 0;
    }   // end of file

This is what I have so far.

I changed the code a little bit and now I have this. In the output it allows me to input one salary but it is not allowing me to enter a negative number to stop

#include <iostream>
    #include <iomanip>

    using namespace std;
    int main ()
    {
        // variables
        double salary = 1.0;
        double RATE = .03;


        // display raises with 2 decimal places
        cout << fixed << setprecision(2);

        //begin loop 
        while (salary > 0.0) 
        {
            // enter salary
            cout << "Salary (negative number to stop): "; 
            cin >> salary;

            cout << "Annual Raises for next three years: " << endl;

            // while loop to calculate annual raises
             while (RATE < .06) 
             {
                // display annual raise amount
                cout << RATE * 100 << "% raise: ";
                cout << salary * RATE << endl;

                // update salary value and annual raise rate.
                salary += (salary * RATE);
                RATE += .01;

             } //end of inner loop
        }   // end of outer loop
            return 0;
    }   // end of file

When you enter a negative number, what do you do with it? You process it as if it was a salary.

After RATE = 0.06, you loop back, to get a new salary, but RATE is still 0.06. Is this what you intended?

No I need to be able to input a negative number and the program end.

So what do you need to add to the code to see if a negative number was entered?
If a negative number was entered, do you want to process it as a salary or do something else?

I need it to end the program if I enter a negative number.

I repeat:

When you enter a negative number, what do you do with it? You process it as if it was a salary.

... what do you need to add to the code to see if a negative number was entered?

I found the problem and the problem is solved. Thanks for everyones help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.