Needs a While Statement

Ok, I have got this and now I am not sure how to do a While statment. Could someone help me understand. I need to incorporate a 'While" statenent.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
 #include <iomanip>
 
using namespace std;
int main()
{
 //declare variables
 
 double year1 = 0.0;
 double year2 = 0.0;
 double year3 = 0.0;
 double salary = 0.0;
 double raise = 0.0;
 double totalSalary = 0.0;
 const double rate = .05;
 
//Enter Salary
 cout << "Enter Annual Salary: $ " ;
 cin >> salary;


 
// Calculation
 
year1 = salary *(1.+ rate);
year2 = year1 * (1.+ rate); 
year3 = year2 * (1.+ rate); 
totalSalary = year1 + year2 + year3; 

cout << fixed << setprecision(2);
 
 cout << "After Year 1: $ " << year1 << endl;
 cout << "After Year 2: $ " << year2 << endl;
 cout << "After Year 3: $ " << year3 << endl;
 cout << "Total salary for the three years:$ " << totalSalary << endl;
 
system("pause");
 return 0;
 } //end of main function 
closed account (zb0S216C)
A while loop is one of the simplest loop forms. It starts with a condition. The condition evaluates to either true or false. If the condition evaluates to true, the loop goes again. Otherwise, it will stop. For example:

1
2
3
4
5
6
int Counter( 0 );
while( Counter <= 10 )
{
    // Do something useful...
    ++Counter;
}

In this code, before while starts another cycle, it tests the condition. If Counter is less than or equal to 10, it will perform another cycle. If not, the loop will stop. The condition is tested before every cycle. If the condition is false, the body of the loop is never entered.

Wazzak
Topic archived. No new replies allowed.