게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
c++코딩했는데 에러좀 봐주세요....ㅠ
게시물ID : computer_8668짧은주소 복사하기
작성자 : 까망보이
추천 : 0
조회수 : 3079회
댓글수 : 3개
등록시간 : 2011/06/19 01:34:18
 #include <iostream>
#include <cmath>
using namespace std;
#define pi = 3.1415
#define permi = (8.85 * pow (10,-12))

const double s,a=0.001, b= 0.01, l=0.1 ;
double q=100;  
double *pq; 

void other()
{
double electf, false_electf;
if ( a < s &&  s < b)// 가우스 폐곡면 s 범위: a와 b 사이 일때
{
  *pq =q;                                                              // 포인터 *pq
  cout << " 전기장[E] 구해봅시다. " << endl;
  cout << " s [가우스 폐곡면 반지름] 값을 입력하시오 ."<< endl;
  cin >>  s;
  electf = (*pq)/(2 * pi * permi * l * s);                 //자장 공식.  
  cout << "E-field :  " << electf <<endl
}
else if ( a > s ||  s > b)                             // s 가 a와b 사이를 벗어나면

  *pq =0;                                                    //  Q=0 가 되어서 E-field 는 없다.
  false_electf = *pq/(2 * pi * permi * l * s);    // Q=0 이 되므로 자장은 0이 나옴.=>error
  cout << " 가우스 폐곡면의 원통반지름의 범위 s가 sb 이면" << endl;  
  cout << false_electf << endl;

}


void main()
{
double potv;
    double d, capaci;
    cout << " C++ 로 원통형 축전기의 E, V , C  구해봅니다. " << endl;
other();                                                              // othet()함수를 불러서 실행한다.

double ds = 0;
for ( double n=1 ; n<=100 ; n++ )                     // ln(a/b) 을 for 문을 돌려서 계산하였다.
{
  d= (b - a)/100;
  ds+= 1/(a+d*n)*d;
}
potv= q/(2 * pi * permi * l )* ds;                              //포텐셜 구하는 공식  => error
cout << " potential[V] : " << potv << endl;   
capaci = q / potv;                                                      //캐퍼시터 구하는 공식
    cout << " capacitor [= Q/V] :  " << capaci << endl; 
}



------ 빌드 시작: 프로젝트: j, 구성: Debug Win32 ------
컴파일하고 있습니다...
a.cpp
c:\documents and settings\a\바탕 화면\j\j\a.cpp(7) : error C2734: 's' : const 개체는 extern이 아닌 경우 초기화될 수 있습니다.
c:\documents and settings\a\바탕 화면\j\j\a.cpp(19) : error C2679: 이항 '>>' : 오른쪽 피연산자로 'const double' 형식을 사용하는 연산자가 없거나 허용되는 변환이 없습니다.
        c:\program files\microsoft visual studio 9.0\vc\include\istream(1144): 'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char *)'일 수 있습니다.
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(1146): 또는       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,signed char &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(1148): 또는       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(1150): 또는       'std::basic_istream<_Elem,_Traits> &std::operator >><std::char_traits<char>>(std::basic_istream<_Elem,_Traits> &,unsigned char &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(155): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_istream<_Elem,_Traits> &(__cdecl *)(std::basic_istream<_Elem,_Traits> &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(161): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(168): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::ios_base &(__cdecl *)(std::ios_base &))'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(175): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::_Bool &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(194): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(short &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(228): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned short &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(247): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(int &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(273): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned int &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(291): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(309): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__w64 unsigned long &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(329): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(__int64 &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(348): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(unsigned __int64 &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(367): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(float &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(386): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(double &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(404): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(long double &)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(422): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(void *&)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        c:\program files\microsoft visual studio 9.0\vc\include\istream(441): 또는       'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'
        with
        [
            _Elem=char,
            _Traits=std::char_traits<char>
        ]
        인수 목록 '(std::istream, const double)'을(를) 일치시키는 동안
c:\documents and settings\a\바탕 화면\j\j\a.cpp(20) : error C2059: 구문 오류 : '='
c:\documents and settings\a\바탕 화면\j\j\a.cpp(22) : error C2143: 구문 오류 : ';'이(가) '}' 앞에 없습니다.
c:\documents and settings\a\바탕 화면\j\j\a.cpp(26) : error C2059: 구문 오류 : '='
c:\documents and settings\a\바탕 화면\j\j\a.cpp(46) : error C2059: 구문 오류 : '='
빌드 로그가 "file://c:\Documents and Settings\a\바탕 화면\j\j\Debug\BuildLog.htm"에 저장되었습니다.
j - 오류: 6개, 경고: 0개
========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========


오류가 뭔말인지도 모르는게 막 튀어나오는데 

이게 뭔가요....ㅠㅠ
오류메세지는 검색하다보니깐...

const object must be initialized if not extern
(const 객체는 extern이 아닐경우 초기화되어야 합니다)
error C2679
에러가 표출된 후에는 해당 연산자의 원형을 표출합니다.
error C2143: 구문 오류 : ';'이(가) '}' 앞에 없습니다.
말 그대로 입니다.
error C2059
#define 구문으로 인한 치환은 컴파일보다 먼저 실행됩니다.

이것만 가지고 오류수정을 못할거같아 오유유저분께 도움 부탁드립니다...ㅠ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호