坚持在循环 [英] Stuck on While Loop

查看:81
本文介绍了坚持在循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行一项名为Pennies for Pay的课程作业

该计划的目标是接收工作天数的输入。

这应该是> 0和< = 40。


示例输出如下,您会注意到,每天的工资翻倍。


支付:$ .01在第1天。总工资$ .01

支付:第2天$ .02。总工资$ .03

支付:第3天$ .04。总工资$ .07

支付:第4天$ .08。总工资$ .15

支付:第16天$ .16。总工资$ .31

一直持续到天数。


我的程序如下:我唯一的问题是,当用户输入工作天数时,它来自那一天,一直到40,而不是从第一天开始直到工作天数。


我想我可能需要调整while循环....任何建议?

I am working on a class assignment called Pennies for Pay
the object of the program is to receive input for number of days worked.
This should be > 0 and <= 40.

An example output is below and you will notice, the pay doubles each day.

Pay: $.01 on day 1. Total Salary $.01
Pay: $.02 on day 2. Total Salary $.03
Pay: $.04 on day 3. Total Salary $.07
Pay: $.08 on day 4. Total Salary $.15
Pay: $.16 on day 5. Total Salary $.31
continue until number of days.

My program is below: The only problem I have is that when a user inputs the number of days worked, it goes from that day, all the way until 40 instead of from the first day until the number of days worked.

I think I may need to tweak the while loop....any suggestions?

展开 | 选择 <跨度 class =codeDivider> | Wrap | 行号

推荐答案

.01第1天。总薪资
.01 on day 1. Total Salary


0.01

支付:
.01
Pay:


.02第2天。总薪资
.02 on day 2. Total Salary


这篇关于坚持在循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆