Need help adding a while loop to my codeblock. Newbie here, having some trouble!

This is the codeblock I'm working on, and I need to implement a while loop to run it infinitely until it is untrue.
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
// GrossPay.cpp : Defines the entry point for the console application.
//int temp = 0;
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
    using namespace std;

        int main()
        {
            double hourly_rate;
            double hours;
        double gross_pay;
        while ( gross_pay >= 1 ) {
        printf("Please input the hourly rate of the employee: ");
        cin >> hourly_rate;
        printf("Please input the number of hours worked by the employee: ");
        cin >> hours;

        if (hours <= 40)
        {
            gross_pay = hours * hourly_rate;
        }
        else
        {
            gross_pay = (40 * hourly_rate) + (hours - 40) * (hourly_rate * 1.5);
        }

        cout << "The gross pay of this employee is $" << gross_pay << "." << endl;

        system("pause");
        return 0;
    }
}
Until what is untrue?
until the returned result is 0. It's for a school assignment. This is my first time trying to implement a loop, so I just need to understand how to correctly write out the loop and what condition I should use.
Oh, I see what your problem is, changes commented.

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
// GrossPay.cpp : Defines the entry point for the console application.
#include <iostream>
using namespace std;

int main()
{
	double hourly_rate;
	double hours;
	double gross_pay = 1;//initialize variable
	while (gross_pay >= 1) {
		printf("Please input the hourly rate of the employee: ");
		cin >> hourly_rate;
		printf("Please input the number of hours worked by the employee: ");
		cin >> hours;

		if (hours <= 40)
		{
			gross_pay = hours * hourly_rate;
		}
		else
		{
			gross_pay = (40 * hourly_rate) + (hours - 40) * (hourly_rate * 1.5);
		}

		cout << "The gross pay of this employee is $" << gross_pay << "." << endl;

		
	}
	return 0;//return goes out side loop
}
Nice! Ok, so I input the changes you have made, and the program runs! You are amazing! Thanks for the help that you provided. Now I can work on learning these loops more thoroughly.
Topic archived. No new replies allowed.