2013-03-01 1 views
0

EDIT : If-Else가 있습니다. 무슨 일이 일어나는지보십시오. 그리고 누군가가 대답을 잘못하면 어떻게 돌아갈 지 말해 줄 수 있습니까? 마찬가지로, 부정확 한 대답으로 다시 입력 하시겠습니까?C++ 입력 할 때 계속하지 않고 프로그램이 끝납니다

using namespace std;

int main() 
{ 

cout<<"Welcome to the Grade Database. Please insert your domain: " ; 
cout<<"\n"; 
int d, n; 
cin>>d; 
cout<<"Now enter your total grade(between 0-100): " ; 
cin>>n; 
if (n>0 && n<59){ 
    cout<<"See you next year then :(" ; 
    cout<<"F-"<<n;} 
else if (n<60 && n>=69){ 
    cout<<"Well...you pass ;D" ; 
    cout<<"E-"<<n<<" ~"<<d;} 
else if (n>70 && n<=79){ 
    cout<<"Better than the average!"; 
     cout<<"D-"<<n<<" ~"<<d ;} 
else if (n>80 && n<=89){ 
    cout<<"Very well sir!"; 
    cout<<"C-"<<n<<" ~"<<d;} 
else if (n>90 && n<=99){ 
    cout<<"Wow, amazing! One of the best!"; 
    cout<<"B-"<<n<<" ~"<<d;} 
else if(n==100){ 
    cout<<"Well, hello there Mr. Stephen Hawking."; 
    cout<<"A-"<<n<<" ~"<<d;} 
else{ 
    cout<<"Invalid Entry.";} 

return 0; 

} C++에서

+1

'switch'는 조건을 사용할 수 없습니다 (조건은 단지 표현식이고 표현식은 명령문으로 허용되기 때문에 컴파일됩니다.하지만 실제로는 아무 것도하지 않습니다). if- 그밖에. – Cameron

+0

내가 편집했습니다. 어떻게 생각해? –

+0

Ok, 아직 작동하지 않습니다 :(심지어 endl; –

답변

5

switch이 범위 또는 조건을 지원하지 않습니다 만 정확히 일치합니다. 당신이 조건을 가지고 있기 때문에,이 같은 ifelse을 사용해보십시오 :

cin>>n; 
if (n>0 && n<59) { 
    cout<<"See you next year then :(" ; 
    cout<<"F-"<<n; 
} 
else if (n>=60 && n<=69) { 
    cout<<"Well...you pass ;D" ; 
    cout<<"E-"<<n<<" ~"<<d; 
} 
else if (n>=70 && n<=79) { 
    cout<<"Better than the average!"; 
    cout<<"D-"<<n<<" ~"<<d ; 
} 
else if (n>=80 && n<=89) { 
    cout<<"Very well sir!"; 
    cout<<"C-"<<n<<" ~"<<d; 
} 
else if (n>=90 && n<=99) { 
    cout<<"Wow, amazing! One of the best!"; 
    cout<<"B-"<<n<<" ~"<<d; 
} 
else if (n==100) { 
    cout<<"Well, hello there Mr. Stephen Hawking."; 
    cout<<"A-"<<n<<" ~"<<d; 
} 
else { 
    cout<<"Invalid Entry."; 
} 

당신은 아마 일부 줄 바꿈 문자를 원한다. 두 번째로 cout <<을 쓰면 새 라인이 시작되지 않고 std::endl을보십시오.

+0

음, "using namespace std;"를 사용할 수 있다는 것을 알고 있습니다. cout/cin을 위해. 하지만 조언 주셔서 감사합니다, 3 –

관련 문제