探索测试之路。。。

lr习题+答案-Exercise 3.2

上一篇 / 下一篇  2007-08-29 14:16:22 / 个人分类:Loadrunner

Exercise 3.2

 

a)      You invest  $10,000 in a special account that pays 10% interest at the end of each year on the beginning balance of the year. You decide to take your investment out as soon as it doubles. Write a program that will print out the year, beginning balance, interest gained for the year and the ending balance for the year. This program should stop as soon as the ending balance reaches $20,000. All dollar amounts should be printed to a precision of 2 decimals.

Here is what a sample output might look like:

 

Virtual User scrīpt started

Running Vuser...

Starting iteration 1.

Actions.c(18):Year = 1, Beginning Balance = 10000.00, Interest = 1000.00, Ending Balance = 11000.00

Actions.c(18):Year = 2, Beginning Balance = 11000.00, Interest = 1100.00, Ending Balance = 12100.00

Actions.c(18):Year = 3, Beginning Balance = 12100.00, Interest = 1210.00, Ending Balance = 13310.00

Actions.c(18):Year = 4, Beginning Balance = 13310.00, Interest = 1331.00, Ending Balance = 14641.00

Actions.c(18):Year = 5, Beginning Balance = 14641.00, Interest = 1464.10, Ending Balance = 16105.10

Actions.c(18):Year = 6, Beginning Balance = 16105.10, Interest = 1610.51, Ending Balance = 17715.61

Actions.c(18):Year = 7, Beginning Balance = 17715.61, Interest = 1771.56, Ending Balance = 19487.17

Actions.c(18):Year = 8, Beginning Balance = 19487.17, Interest = 1948.72, Ending Balance = 21435.89

Ending iteration 1.

Ending Vuser...

 

 

My Answer:

Action8()
{
 int Year=1;
 float Interest = 0.1;
 float BeginningBalance = 10000;
 float EndingBalance = 0;
 while (EndingBalance<20000)
 {
  EndingBalance = BeginningBalance*0.1+BeginningBalance;
  BeginningBalance = EndingBalance;
  lr_output_message("Year=%d,Beginning Balance=%.2f,Interest=%.2f,Ending Balance=%.2f",Year,BeginningBalance,EndingBalance*Interest,EndingBalance);
  Year++;
 }
 return 0;
}


TAG: Loadrunner

 

评分:0

我来说两句

Open Toolbar