|
发表于 2013-3-19 18:06:21
|
显示全部楼层
原来改了代码。要实现你的功能你还差了几步
首先scanf之前要清除缓冲,好像之前以前已经和你说了。
其次你要实现重复输入,没有循环怎么能行呢?所以要在switch外围加上个循环,当条件满足了再跳走。
修改代码:
- //#include "StdAfx.h"
- #include <stdio.h>
- #include<conio.h>
- void main()
- {
- double r1 , r2 , pa ;
- char name[10] ;
- char a ;
- printf("Hello, Please input your name:");
- scanf("%s" , &name);
- printf("Hi, %s, Welcome to use this programe!\n",name);
- printf("Please input one resistor value:");
- scanf("%lf" , &r1);
- printf("Please input other resistor value:");
- scanf("%lf" , &r2);
- while(true)
- {
- if( r1==0 && r2==0 )
- {
- printf("Sorry, the resistance can not be both zero.\n");
- printf("If input again? (y/n)");
- flushall();
- scanf("%c" , &a);
- switch(a)
- {
- case 'y':
- printf("Please input one resistor value:");
- scanf("%lf" , &r1);
- printf("Please input other resistor value:");
- scanf("%lf" , &r2);
- break;
- case 'n':
- goto loop;
- break;
- }
- }else
- break;
- }
- pa = (r1*r2)/(r1+r2);
- printf("The parallel value is %lf .\n" , pa);
- printf("The series value is %lf .\n" , r1+r2);
- loop:
- printf("\nThank you for using the program.");
- getch();
- }
复制代码
|
|