| 
학교 프로그래밍시간에 하는 건데요 if else 를 사용해서 돌려야하는 옴의 법칙 계산 ( V = I x R )프로그램인데 
 몇 시간을 매달려도 도통 안되네요..T.T..
 
 프로그램을 실행 시켜서 나오는 4개의 보기중 하나를 선택하고나서 나머니 2개의 값을 입력하면 답을 구해주고
 
 나서 이 프로그램을 끝낼꺼냐구 묻는데 여기서 y면 끝내구 n면 다시 프로그램을 실행시켜야 하는데 이 부분에서
 
 막혀서요.. 뭐가 잘못됬는지.. 아~! goto 명령어 쓰지 말고 if 랑 else만 사용해야하는데요.. 에구.. 도움좀 부탁드려요~
 
 (참고로 Turbo C++ 1.00을 사용합니다~ ^^;)
 
 #include <stdio.h>
 #include <conio.h>
 #include <stdlib.h>
 
 main ()
 
 {
 float V, I, R;
 int choice;     // this variable used for choice
 char reply;
 
 /*** Input Stage ***/
 clrscr();
 printf ("This program calculates V or I or R using Ohm's Law\n");
 printf ("\nChoose a number to calculate:");
 printf ("\n1. Voltage");
 printf ("\n2. Current");
 printf ("\n3. Resistance");
 printf ("\n0. Exit");
 printf ("\n > ");
 scanf("%d", &choice);
 
 /*** Processing Stage for 1 ***/
 if (choice==1)
 
 {
 printf ("\nEnter current > ");
 scanf("%f", &I);
 printf ("\nEnter resistance > ");
 scanf("%f", &R);
 V = I * R;
 
 /*** Output Stage for 1 ***/
 printf ("\nThe volatge is %.2f volts\n", V);
 printf ("\ndo you want to quit (y/n) > ");
 fflush(stdin);
 scanf ("%c", &reply);
 
 if (reply == 'y' || reply == 'Y')
 exit(0);
 }
 
 /*** Processing Stage for 2 ***/
 else if (choice==2)
 
 {
 printf ("\nEnter voltage > ");
 scanf("%f", &V);
 printf ("\nEnter resistance > ");
 scanf("%f", &R);
 I = V / R;
 
 /*** Output Stage for 2 ***/
 printf ("\nThe current is %.2f amps\n", I);
 printf ("\ndo you want to quit (y/n) > ");
 fflush(stdin);
 scanf ("%c", &reply);
 
 if (reply == 'y' || reply == 'y')
 exit(0);
 }
 
 /*** Processing Stage for 3 ***/
 else if (choice==3)
 
 {
 printf ("\nEnter voltage > ");
 scanf("%f", &V);
 printf ("\nEnter current > ");
 scanf("%f", &I);
 R = V / I;
 
 /*** Output Stage for 3 ***/
 printf ("\nThe resistance is %.2f ohms\n", R);
 printf ("\ndo you want to quit (y/n) > ");
 fflush(stdin);
 scanf ("%c", &reply);
 
 if (reply == 'y' || reply == 'y')
 exit(0);
 }
 
 /*** Processing Stage for 0 ***/
 else if (choice==0)
 
 {
 /*** Output Stage for 0 ***/
 printf ("\nQuitting... Hit Any Key to Exit");
 fflush(stdin);
 getch();
 exit(0);
 }
 }
 |