Effective January 1st of each year, Gabriela receives a 5% raise on
her previous year’s salary. She wants a program that calculates and
displays the amount of her annual raises for the next three years. The
program also should calculate and display her total salary for the
three years.

Annual salary is $10,000. (The raise amounts
are $500.00, $525.00, and $551.25. The total salary is $33,101.25.)

***I am supposed to have a post loop but not sure how to do this****

// keith joyner 10/25/14 ch7ex31

#include <iostream>
#include <iomanip>
using namespace std;

int main ()

    //declare variables
    const double RATE= 0.05;
    double salary= 0.0;
    const double raise= 0.05;
    int year= 1;
    double totalSalary = 0.0;
    int counter = 0;
    double previousYearsSalary = 0.0;

    //enter user input
    cout <<  "Enter First Year's Salary (-1 to stop): " ;
    cin >> salary;

    //begin loop

        cout << "Year: = $ " << year << "raise: = $" << raise << endl;

        for (raise = salary * RATE);

            (salary = salary + raise);

            (totalSalary += salary);

    cout << "Salary: = $ " << setprecision(2) << fixed << salary  << endl;
    cout << "Previous Years Salary: = $ " << previousYearsSalary << endl;

    } // end for 

    //update years counter
    year += 1;

}   while (year < 4);

system ("pause");
        return 0;
}// end main function

Recommended Answers

All 2 Replies

tried following the excercise but its just not making since, and my teacher is horrible at getting this to make since, hence she does not teach it like there are people who dont know what they are doing like me, she just expects everyone knows what there doing right to get go.

It looks like you are trying to do everything at once without taking the time to learn the details.

For example, you can declare variables global before declaring main(), but not after. To make the variables local to main() then use an opening curly brace after declaring main and stareting the list.

It looks like you learned about the keyword const, but not when to use it. For example, the variable raise should go up every year, so it shouldn't be const.

Loops can be for, while or do/while, but while can't can't appear after the body of a loop without do appearing before the body of the loop.

Placing a semicolon after the closing brace of a for loop declaration is a common error. You don't want it.

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.