Hello! a beginner with C++ Programming& I need help

Okay! I really need your help or some t开发者_开发百科ips I need a program that I will recieve a raise on my previous years salary. I need to calculate and display the amount of annual raises for the next three years. I want to use the rates o 3% 4% 5% and 6%.
This is what I have so far but its not working
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    int beginSalary  = 0;
    double newSalary = 0.0;
    double raise     = 0.0;
    double theRate = 0.0;
    cout << "Beginning Salary (negative number or 0 to end): ";
    cin >> beginSalary;
 do 
 {
        // 3 percent
        newSalary = (beginSalary+(beginSalary*3/100)); 
        raise = newSalary-beginSalary; 
        cout << raise << endl; 
        cout << endl;
        // 4 percent
        newSalary = (beginSalary+(beginSalary*4/100)); 
        raise = newSalary-beginSalary; 
        cout << raise << endl;
        // 5 percent
        newSalary = (beginSalary+(beginSalary*5/100)); 
        raise = newSalary-beginSalary;  
        cout << raise << endl; 
        cout << endl;
        // 6 percent
        newSalary = (beginSalary+(beginSalary*6/100)); 
        raise = newSalary-beginSalary; 
        cout << raise << endl; 
        cout << endl;
    } while ( newSalary != 0);
    return 0;
}   //end of main function
What you want to do is this:
int beginSalary;
do {
    cout << "Beginning Salary (negative number or 0 to end): ";
    cin >> beginSalary;
    if (beginSalary <= 0) break;
    for (int percent = 3; percent <= 6; percent++)
    {
        cout << endl << "Raise for " << percent << "% for the next three years: " << endl;
        double salary = beginSalary;
        for (int year = 1; year <= 3; year++)
        {
            double raise = salary * percent / 100.0;
            salary += raise;
            cout << "Year " << year << ": " << raise << ". ";
        }
    }
} while (1);
cin >> ...
should be inside the loop. or you'd have an endless loop.
or a different loop condition would be better
The problem is in the input request:
you have to move the CIN instruction inside your loop. The loops repeat only the part inside the block {}.
The while condition need to be changed too, because with != 0 you won't ask again on negative value (as stated in the cout sentence)
   cout << "Beginning Salary (negative number or 0 to end): ";
 do 
 {
    cin >> beginSalary;
//A LOT OF CODE
} while ( newSalary <= 0);
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论