This is what I have done so far
double minPayRate = 7.5;
double maxPayRate = 49.99;
double inputNumber;
int count = 0;
while (true)
{
inputNumber = Convert.ToDouble(inPutTextBox.Text);
if (inputNumber >= minPayRate && inputNumber <= maxPayRate) break;
count++;
if (count == 2)
outPutLabel.Text = " You had used your two tries to enter valid hourly payment";
return;
}
outPutLabel.Text = " Hourly pay rate {0:C}, while weekly pay rate is {1:C}", inputNumber, inputNumber * 40);
My problem is , how do i set button invisible after 2 tries? And I also have an error on last line for some reason, please help
Loading
VulpesPosted Dec 29, 2011, 4:21 AM
Sam HobbsPosted Dec 29, 2011, 8:25 PM
Prime bPosted Dec 29, 2011, 7:35 PM
Sam HobbsPosted Dec 29, 2011, 7:22 PM
VulpesPosted Dec 29, 2011, 6:56 PM
Prime bPosted Dec 29, 2011, 6:32 PM
VulpesPosted Dec 29, 2011, 6:00 PM
Prime bPosted Dec 29, 2011, 4:42 PM
VulpesPosted Dec 29, 2011, 4:23 PM
Prime bPosted Dec 29, 2011, 1:49 PM
I also have a problem, the inputNumber = double.TryParse(inPutTextBox.Text,out inputNumber); line gives me an error saying " Cannot implicitly convert type 'bool' to 'double' " , how can I fix that?
Also, why we always put curly brackets around every if and else statements?
Prime bPosted Dec 28, 2011, 11:19 PM
Sam HobbsPosted Dec 28, 2011, 11:10 PM
Prime bPosted Dec 28, 2011, 10:33 PM
Prime bPosted Dec 28, 2011, 6:58 PM
But this is what I am talking about
3. a. Write a console-based program that prompts a user for
an hourly pay rate. If the user enters values less than $7.50
or greater than $49.99, prompt the user again. If the user
enters an invalid value again, display an appropriate error
message. If the user enters a valid value on either the
fi rst or second attempt, display the pay rate as well as the
weekly rate, which is calculated as 40 times the hourly
rate. Save the program as SecondChancePayRate.cs.
b. Create a GUI application similar to the one described in
Exercise 3a. Allow the user to click a button to submit a
rate. After the user has made a valid entry, or after two
invalid entries, make the button invisible. Save the project
as SecondChancePayRateGUI.
This is not homework, I am just practicing before 2nd C# semester will start.
I have done 3a, vulpes helped me, you can see it here http://www.c-sharpcorner.com/Forums/Thread/154660/second-chance.aspx
But I need help in 3b, to make button hidden after 2 times wrong entry!
Sam HobbsPosted Dec 28, 2011, 6:03 PM
Sam HobbsPosted Dec 28, 2011, 6:03 PM
I don't know what you are trying to do in the last line so I do not know how to fix it.
Note that in your while loop, you are calling return so the loop will always be executed only once. You probably need to use curly brackets ("{}") for your if statement so the return is executed only when count is 2.
Prime bPosted Dec 28, 2011, 5:53 PM