This is a problem form the book \"starting out with APP INVENTOR FOR ANDROID\" b
ID: 3691843 • Letter: T
Question
This is a problem form the book "starting out with APP INVENTOR FOR ANDROID" by Tony Gaddis and Rebecca Halsey. The answer needs to be run on the emulator connected to the AIStarter. Susan is hired for a job, and her employer agrees to pay her every day. Her employer also agrees that Susan's salary is 1 penny for the first day, 2 pennies for the second day, 4 pennies for the third day, continuing to double each day. Create an app that allows the user to enter the number of days that Susan will work and calculates the toatl amout of pay she will recieve over that period of time.
Explanation / Answer
Answer:)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace pennies_for_Pay_JWA
{
public partial class penniesForPayCalcJWA : Form
{
public penniesForPayCalcJWA()
{
InitializeComponent();
}
private void calculateBtnJWA_Click(object sender, EventArgs e)
{
// Variables initialization
int count = 1; // Loop control variable
int days = 1; // days worked
double currentPay = 0; // The current pay
double totalPay = 0; //total pay
// get the number of days
if (int.TryParse(daysWorkedTxtBoxJWA.Text, out days))
{
for (count = 1; count <= days; count++)
{
//calculations display
currentPay = .01 * Math.Pow(2, days-1);
totalPay += currentPay;
//add one to the count loop
count = count + 1;
}
//display the ending balance
totalPayLblJWA.Text = totalPay.ToString("c");
}
else
{
//Invalid number of days entered
MessageBox.Show("Invalid value for days.");
}
}
private void clearBtnJWA_Click(object sender, EventArgs e)
{
// clear data fields
daysWorkedTxtBoxJWA.Text = "";
totalPayLblJWA.Text = "";
}
private void exitBtnJWA_Click(object sender, EventArgs e)
{
//close the program
this.Close();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.