无尽的循环问题 [英] Endless loop question

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

问题描述

本周这一直困扰着我。这实际上是一个家庭作业

作业

来自上个学期。但是老师不会告诉我们为什么某些东西没有用,但它并没有起作用。我的事情是什么

实际上将这个循环转换为无限循环而不是等待用户响应
它将会跳过它。可能有人用

的时间向我解释一下这会使它表现得如此

int pts1,pts2,pts3,wk_exp,p_pay,total_pts,total_pay;

char degree,再次;


int main(){

char =''Y'';


while(再次!=''N'')

{


printf(" \ nEnter degree type:(B对于学士学位),(M代表硕士学位),(D

代表Doctorate \ n");

printf(" \t\t\t: ");

scanf("%1c",& degree);

if(degree =''B''){

pts1 = 3;

}

if(degree =''M''){

pts1 = 5;

}

if(degree =''D''){

pts1 = 7;

}

printf(\ n输入工作年数:);

scanf("%2d",& wk_exp);

if(wk_exp< = 3){

pts2 = 4;

}

i f(wk_exp> = 4&& wk_exp< = 6){

pts2 = 7;

}

if(wk_exp > = 7){

pts2 = 10;

}


printf(" \\\
Enter current Pay:" ;);

scanf("%5d"& p_pay);

if(p_pay< = 15000){

pts3如果(p_pay> = 15001&& p_pay< = 22500){

pts3 = 8;

}

if(p_pay> 22500){

pts3 = 12;

}


total_pts = pts1 + pts2 + pts3;

if(total_pts< = 19 ){

total_pay = 25000;

}

if(total_pts> = 20&& total_pts< = 28){<如果(total_pts> = 29){

total_pay = 35000;

}


printf(" \ n付费率为:%d \ nn",total_pay);


printf(\ n想要再次执行此操作?按N代表NO:);

/ * scanf("%1c",& again); * /

getchar();

}


返回(0);

}

解决方案

ph **** @ yahoo.com (Tweaxor)在

新闻中写道:1c ************************** @ posting.google.c om :

本周一直困扰着我。这实际上是上一学期的作业
作业。但老师不会告诉我们为什么某些事情不起作用,但它不仅仅是有效的。我的事情是什么实际上将这个循环变成无限循环而不是等待用户响应它将会跳过它。有时间的人可以向我解释一下这会使它表现得如此吗


这些似乎都不需要在main()之外定义。

int pts1,pts2,pts3,wk_exp,p_pay,total_pts,total_pay;
char degree,再次;

int main(){
Ick ^^^ ^^^^^


int main(无效)

{

char =''Y'';

while(再次!=''N'')
{
/ * scanf("%1c",& again); * /
getchar();
}
返回(0);

}




因为最初再次==''Y'',解释再怎么会是什么

但是''Y''。然后看看为什么while循环变得无穷无尽。


-

- 马克 - >

-


Mark A. Odell< od ******* @ hotmail.com>写道:

ph****@yahoo.com (Tweaxor)写在
新闻:1c ************************** @ posting.google.c om:

< blockquote class =post_quotes> int main(){


Ick ^^^^^^^^



int main(void)
{




不,为什么?你可以在函数定义中删除'void',不是吗?


-

Stan Tobias

sed 's / [AZ] // g''发送电子邮件


2004年9月29日18:11:07 GMT,S.Tobias < SN ******* @ amu.edu.pl>写道:

Mark A. Odell< od ******* @ hotmail.com>写道:

ph****@yahoo.com (Tweaxor)写在
新闻:1c ************************** @ posting.google.c om:


> int main(){


Ick ^^^^^^^^


int main(void)
{



不,为什么?你可以在函数定义中删除`void',不是吗?




它们意味着不同的东西。 ''(void)''告诉编译器没有

参数。 ''()''告诉编译器参数未指定。


-

Al Balmer

Balmer Consulting
re ******** ****************@att.net


This has been puzzling me all this week. This is actually a homework
assignment
from last semesmter. But the teacher wouldn''t tell us why certain
things didn''t work, but it didn''t just work. My thing was what
actually turn this while loop into an endless loop instead of waiting
for user response it''ll would skip right over it. Could someone with
the time explain this to me what would make it behave like this
int pts1, pts2, pts3, wk_exp, p_pay, total_pts, total_pay;
char degree, again;

int main() {
char again = ''Y'';

while (again != ''N'')
{

printf("\nEnter degree type: (B for Bachelors), (M for Masters), (D
for Doctorate\n");
printf("\t\t\t: ");
scanf("%1c", &degree);
if (degree = ''B'') {
pts1 = 3;
}
if (degree = ''M'') {
pts1 = 5;
}
if (degree = ''D'') {
pts1 =7;
}
printf("\nEnter number of years of work experience: ");
scanf("%2d",&wk_exp);
if (wk_exp <= 3) {
pts2 = 4;
}
if (wk_exp >= 4 && wk_exp <= 6) {
pts2 = 7;
}
if (wk_exp >= 7) {
pts2 = 10;
}

printf("\nEnter current Pay: ");
scanf("%5d",&p_pay);
if (p_pay <= 15000) {
pts3 = 4;
}
if (p_pay >= 15001 && p_pay <= 22500) {
pts3 = 8;
}
if (p_pay > 22500) {
pts3 = 12;
}

total_pts = pts1 + pts2 + pts3;
if (total_pts <= 19) {
total_pay = 25000;
}
if (total_pts >= 20 && total_pts <= 28) {
total_pay = 30000;
}
else if (total_pts >= 29) {
total_pay = 35000;
}

printf("\nThe pay rate is: %d\n",total_pay);

printf("\nWant to do this again? Press N for NO: ");
/*scanf("%1c", &again); */
getchar();
}

return (0) ;
}

解决方案

ph****@yahoo.com (Tweaxor) wrote in
news:1c**************************@posting.google.c om:

This has been puzzling me all this week. This is actually a homework
assignment
from last semesmter. But the teacher wouldn''t tell us why certain
things didn''t work, but it didn''t just work. My thing was what
actually turn this while loop into an endless loop instead of waiting
for user response it''ll would skip right over it. Could someone with
the time explain this to me what would make it behave like this

None of these seem to need to be defined outside of main().
int pts1, pts2, pts3, wk_exp, p_pay, total_pts, total_pay;
char degree, again;

int main() { Ick ^^^^^^^^

int main(void)
{
char again = ''Y'';

while (again != ''N'')
{
/*scanf("%1c", &again); */
getchar();
}

return (0) ;

}



Since again is initially == ''Y'', explain how again will ever be anything
but ''Y''. Then see why the while loop becomes endless.

--
- Mark ->
--


Mark A. Odell <od*******@hotmail.com> wrote:

ph****@yahoo.com (Tweaxor) wrote in
news:1c**************************@posting.google.c om:

int main() {


Ick ^^^^^^^^


int main(void)
{



No, why? You can drop `void'' in function definition, can''t you?

--
Stan Tobias
sed ''s/[A-Z]//g'' to email


On 29 Sep 2004 18:11:07 GMT, "S.Tobias" <sN*******@amu.edu.pl> wrote:

Mark A. Odell <od*******@hotmail.com> wrote:

ph****@yahoo.com (Tweaxor) wrote in
news:1c**************************@posting.google.c om:


> int main() {


Ick ^^^^^^^^


int main(void)
{



No, why? You can drop `void'' in function definition, can''t you?



They mean different things. ''(void)'' tells the compiler there are no
arguments. ''()'' tells the compiler that the arguments are unspecified.

--
Al Balmer
Balmer Consulting
re************************@att.net


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

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