
November 13th, 2013, 03:12 PM
#1
Assistance with Pennies for Pay problem.
I am currently taking a programming class and we are using Visual Studios Express 2010, working out of the Starting Out With Visual C# 2010 2nd edition by Tony Gladdis.
I am completely stuck on a problem, the Pennies for Pay were you earn 1 penny for the first day, 2 pennies for the second day, 4 for the 3rd day and so on.
I am trying to write the code so that you input how many days you work in a textbox and then it shows you how much you made.
Im sure I need to use a loop for this problem and decimal since I will be working with 0.01m but beyond that I have no clue were to start.
Im dont want the anwser just some guidance on were to start and a good reference to view a simular problem.
Thanks in advance for any help

November 13th, 2013, 03:44 PM
#2
Re: Assistance with Pennies for Pay problem.
im at work an my laptop is at home so I cant post what I have but here is the basics of were I am at
decimal salary = 0.01m
int total = 0
int days // days worked
// Get the days worked.
if (decimal.TryParse(nuDaysWorkedTextBox.Text, out days))
for(int i = 1, i <= days, i++)
total += salary;
salary * 2;

November 14th, 2013, 10:41 PM
#3
Re: Assistance with Pennies for Pay problem.
I've made a number of changes to my code thus far. Im still trying to figure out how to do the mathematical part of it.
This is my code so far
Any hints would be greatly appreciated
private void calculateButton_Click(object sender, EventArgs e)
{
// Variables
int number; // Loop control variable
int days; // days worked
decimal totalPay; // The total pay
decimal currentPay; // The currentpay
currentPay = .01m;
totalPay = 0;
// Get the number of days worked.
if (int.TryParse(nuDaysWorkedTextBox.Text, out days))
{
// The following loop calculates ending pay.
for (number = 1; number <= days; number++);
currentPay = currentPay * 2;
totalPay += currentPay;
// Display the pay
TotalpayLabel.Text = totalPay.ToString("c");
}
}
private void exitButton_Click_1(object sender, EventArgs e)
{
// Close this form
this.Close();
}
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
