Turbo-C
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
터보-C 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
Lua 게시판
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C/C++ Q/A
[4906] 조언좀 부탁드릴께요~~ ^^
김기현 [fatesee] 1286 읽음    2005-02-09 18:40
학교 프로그래밍시간에 하는 건데요 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);
}
}

+ -

관련 글 리스트
4906 조언좀 부탁드릴께요~~ ^^ 김기현 1286 2005/02/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.