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

C/C++ Q/A
[4971] loop관련 질문입니다..ㅠ.ㅠ.. 도와주세요~
김기현 [fatesee] 1288 읽음    2005-03-26 23:22
3일동안 머리를 쥐어 짜며 생각했지만.. 도저히 안되네요..

일단 온도 평균값을 구하는 프로그램인데요 (while을 사용해서)

사용자로부터 값을 입력 받아, 받은 값 중에서  최저 와 최고 온도를 구한후 그 평균온도를 산출하고 최저, 최고온도를

보여주어야 하는데요

샘플 결과물이

Enter (ctl-z to stop) > 2
Enter (ctl-z to stop) > 5
Enter (ctl-z to stop) > 1
Enter (ctl-z to stop) >            //ctrl-z 키 눌렀음

The average is 3.00             // 최고와 최저 사이만의 평균일경우 3.00, 입력받은 횟수로 구할 경우2.00
The range of values is 1.00 to 5.00
====================================== 그리고 또 다른 결과물
Enter (ctl-z to stop) > -3
Enter (ctl-z to stop) > -2
Enter (ctl-z to stop) >         //ctrl-z 키 눌렀음

The average is -2.50
The range of values is -3.00 to -2.00
====================================== 그리고 또 다른 결과물
Enter (ctl-z to stop) >

No input, quitting...
======================================

결과가 이렇게 나오도록 해야하구요.. 사용되는 변수들은  1000 이상의 큰 값도 다룰수 있도록끔 해야합니다..

제가 짠 소스는.. 아래와 같구요.. loop(while문)을 사용해야하는데.. 에고..

도저히 제 머리로써는 이 이상은 한계네요.. 물론 제가 짠 소스도 문제가 있구요..ㅠ.ㅠ.. 도와주세요~~!!

========================================
#include <stdio.h>
#include <conio.h>
#include <dos.h>

int Ending (void)
{
  printf("\nHit any key to continue..");
  fflush(stdin);
  getch();
return 0;
}

int main ()
{
float count, temp, high, low, sum, average;
int n;

clrscr();

/*** Input Stage ***/
printf("This program adds together numbers\n");

low=0;
high=0;

sum=0;
count=0;

do
{
  printf("\nEnter (ctl-z to stop) > ");
  n=scanf("%f", &temp);

  if(temp>=0)
  {
    if(temp<low)
      {
      low=temp;
      }

    if(temp>high)
      {
      low=high;
      high=temp;
      }

    if(high<low)
      {
      temp=high;
      high=low;
      low=temp;
      }
  }

  else
  {

    if(temp<low)
      {
      if(high>=low)
        {
        low=temp;
        }

      if(high<low)
        {
        high=low;
        low=temp;
        }
      }

    if(temp>low)
      {
      high=temp;
      }

    if(temp>high)
      {
      low=high;
      high=temp;
      }

    if(high<low)
      {
      temp=high;
      high=low;
      low=temp;
      }
  }

count++;

} while(!(n==-1)||(n==0));

sum=low+high;
     
average = sum / (count-1);

/** Output Stage ***/

printf("\nThe average is %.2f\n", average);

printf("\nThe range of vlues is %.2f to %.2f\n", low, high);

Ending ();

}

+ -

관련 글 리스트
4971 loop관련 질문입니다..ㅠ.ㅠ.. 도와주세요~ 김기현 1288 2005/03/26
4973         Re: 알파님 답변 감사드립니다..^^ 근데요~~ 김기현 1241 2005/03/27
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.