在下面的代碼中,我可能會多次輸入,做一些計算(如最後一個字符)並在最後打印..然後再次輸入直到5次?連續輸入字符如使用循環多次的字符串
#include <iostream>
using namespace std;
int main()
{
char name;
int i=0;
while(i != 5){
while(!(name != '<' || name != '>')){
cin>>name;
//do some calculation with the inputs
//cout<<name;
}
i++;
cout<<name;
//print the result of calculation this loop
}
}
出於某種原因,我不能使用string
,或array
,或break
,並不會比其他iostream
庫。是否有可能使用循環?什麼是替代品?
編輯::在上面的代碼中,我想確定什麼是上次輸入。如果我輸入asdf>
,那麼我得到>>>>>
。我想要它打印>
並返回到循環中,並要求我再拍一次。
目前還不清楚你堅持什麼。 「一些計算」部分?循環5次? – 2013-03-19 16:48:00
假設在上面我輸入'asfas <'我得到'<<<<<'並且程序終止。我不想讓程序終止..相反,我想回到while循環裏面,這讓我更想輸入。 – 2013-03-19 16:48:51