2016-11-28 6 views
0

私はプログラムの2番目の値を入力するとその適切私はプログラムの2番目の値を入力するとその適切

私は性別を入力するとき、それは私に尋ねるべき実行3番目の値に私を取るといない実行3番目の値に私を取るといません程度を入力するが、私は3番目の値を入力し、プログラムが正しく動作しないようにしてください。

#include <iostream> 
#include <stdio.h> 
#include <conio.h> 
int main() 
{ 
    char gender; 
    char degree; 
    int age; 
    printf("Enter Gender (F/M) "); 
    scanf("%c",&gender); 
    printf("Enter Degree "); 
    scanf("%c",&degree); 
    printf("Enter Age "); 
    scanf("%d",&age); 
    if(gender == 'M') 
    { 
     if(degree == 'P') 
     { 
      if(age >= 35 && age <= 50) 
      printf("Good Work"); 
      else 
      printf("Better Luck Next Time"); 
     } 
     else 
     { 
      if(degree == 'G') 
      { 
       if(age >= 22 && age <= 40) 
       printf("Good Work"); 
       else 
       printf("Next Time"); 
      } 
     } 
    } 
    else 
    { 
     if(degree == 'P') 
     printf("Good Work"); 
     else 
     printf("Next Time"); 
    } 
    getch(); 
} 
+1

はこの質問を見てみましょう:http://stackoverflow.com/questions/13542055/how-to-do-scanf-for-single-char-in-c –

答えて

1

使用cin機能の代わりscanf。あなたの問題を解決します。

+0

それが働いていますがそんなに –

+1

ありがとう私の答えを真正な答えとしてマークしてください:) –

0
#include <iostream> 
#include <stdio.h> 
#include <conio.h> 
using namespace std; 
int main() 
{ 
    char gender; 
    char degree; 
    int age; 
    cout<< "Enter Gender (F/M) "; 
    cin>>gender; 
    cout<<"Enter Degree "; 
    cin>>degree; 
    cout<<"Enter Age "; 
    cin>>age; 
    if(gender == 'M') 
    { 
     if(degree == 'P') 
     { 
      if(age >= 35 && age <= 50) 
      printf("Good Work"); 
      else 
      printf("Better Luck Next Time one"); 
     } 
     else 
     { 
      if(degree == 'G') 
      { 
       if(age >= 22 && age <= 40) 
       printf("Good Work"); 
       else 
       printf("Next Time two"); 
      } 
     } 
    } 
    else 
    { 
     if(degree == 'P') 
     printf("Good Work"); 
     else 
     printf("Next Time three"); 
    } 
    getch(); 
} 
関連する問題