2015-12-02 192 views
-1

我是谁不工作if语句里面for或while循环

它只能显示第一COUT进入1个学生信息

或醚它跳过循环,并尽一切下循环它

可以请你帮

int x = 1; 

    while (x <= 10) { 
     ++x; 
     if (x = 1) { 
      cout << "enter 1 student info"; 
      cin >> name >> first >> second >> final>>id; 
     } else if (x = 2) { 
      cout << "enter 2 student info"; 
      cin >> name1 >> first1 >> second1 >> final1 >> id1; 
     } else if (x = 3) { 
      cout << "enter 3 student info"; 
      cin >> name2 >> first2 >> second2 >> final2 >> id2; 
     } else if (x = 4) { 
      cout << "enter 4 student info"; 
      cin >> name3 >> first3 >> second3 >> final3 >> id3; 
     } 
    } 

...

for (int x = 1; x <= 9; x++) { 
      if (x = 1) { 
       cout << "enter 1 student info"; 
       cin >> name >> first >> second >> final>>id; 
      } 
      if (x = 2) { 
       cout << "enter 2 student info"; 
       cin >> name1 >> first1 >> second1 >> final1 >> id1; 
      } 
      if (x = 3) { 
       cout << "enter 3 student info"; 
       cin >> name2 >> first2 >> second2 >> final2 >> id2; 
      } 
      if (x = 4) { 
       cout << "enter 4 student info"; 
       cin >> name3 >> first3 >> second3 >> final3 >> id3; 
      } 
     } 

回答

6

我刚才告诉你的第一个错的,如果在您使用=(赋值运算符),而不是==(等于运算符)

int x=1; 

while (x<=10) 
{++x; 
    if(x==1) 

欲了解更多信息看CPP引用或wikipidia

+2

“做作经营者”这是一个新的 –

+0

对不起,只是一个法语单词,谢谢编辑:) – Jerome