I am having a little trouble with my program assignment. I don't want the answer I just need pointed in the wrtie direction.
I cannot get my program to loop. The program prompts user to enter hours worked and calculates and displays. The it asks the user to enter y for yes to continue entering more data. I get to there and then it stops. Below is my code that I have written. Can anyone give me suggestions? Thanks

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

void weeklySalary();
    
    double wage;
	int hours = 0;
	double overtime = 10;
	const int per_wk = 40;
	double regpay = 0;
	double doubletime = 0;
	double overtimepay = 0;
	char y;
    char response;

int main()
{	
    weeklySalary();
    
	cout << "\n\nIs there more data to enter? Select y to resume.\n";
    cin >> response;

    if(response == 'y' || response == 'Y')
	{
	cout << weeklySalary << endl;	
	}
	else
	cout << "Ending Program. " << endl;
	
    return 0;
}

void weeklySalary()
{
    	cout << "Enter number of hours worked for the week. \n";
		cin >> hours;
        cout << "Enter hourly wage: \n";
	    cin >> wage;
				
        regpay = per_wk * wage;
        overtime = hours - per_wk;
		
		
   	   if (overtime <=10)
	    {
   		    overtimepay = overtime * 1.5 * 10.00;
	        doubletime = 0;
		}
	   else
	   
		if (overtime >10)
		{
		    overtime = hours - per_wk;
		    overtimepay = 10 * 1.5 * 10.00;
   	        doubletime = overtime - 10;
		    doubletime = doubletime * 2 * 10.00;
	    }
	   else;
	   
		   cout << "\n\nRegular Pay:      $" << regpay << endl;
	       cout << "Time-and-a-half:  $" << overtimepay << endl;
   	       cout << "Double Time:      $" << doubletime << endl;
	       cout << "Total:            $" << regpay + overtimepay + doubletime << endl;
}

<< moderator edit: added code tags: [code][/code] >>

I only took a quick look, but it sounds like the old newline left over in the input buffer thing: you type Y<cr>; you grab the 'Y' and the next time through you end up getting the '\n', which is not a 'Y'.

I took another look but now when I respond with y and enter I get the following instead of looping:
0041C05A
Now what am I doing wrong?

Where is your loop?

What is that variable that you are streaming out?

You also have an error in one of your calculations.

I have modified your program and it seems to work now once you figure out the above comments that I made.

Take care,
Bruce

The Program is to go through all the steps first. Asking the user to enter the data. When they are finished that is when the prompt to continue begins. I used the weeklySalary to begin the program and then to go to the question of do you want to enter more data. I tried a while loop and then it went crazy and made it an infinite loop.
On my calculations I notice that I need to make the portion where I multiple the overtime * 1.5 * wage not 10.00. And I need to change this in all the areas used.
I need to change my double overtime to int. And I will get rid of the newline.
Am I getting any closer?

Put your loop back in. If it still an infinite loop, I will look at it for you.

Bruce

hi buddy

i suppose that u have not put the piece of code asking for more data in a loop
i think that u'll solve it by doing so

have a nice day

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.