我有這樣的:如何將while循環變成do while循環?
#include <iostream>
using namespace std;
int main()
{
char ch, max = 0;
int n = 0;
cout << "Enter number of characters! :";
cin >> n;
cout << "Enter the number";
while (n>0)
{
cin >> ch;
if(max<ch)
max = ch;
n=n-1;
}
cout << "max is : " << max;
}
我試圖把它變成一個do while循環 - 這是我有:
int main()
{
char ch, max = 0;
int n = 0;
cout << "enter character";
cin >> n;
cout << "enter two";
cin >> ch;
do
(max<ch);
while
(max = ch);
(n>0);
n= n - 1;
cout << "max is : " << max;
}
我該如何解決這個問題?
是您的實際代碼還是發佈時發生錯誤。 –
你想做什麼? – cpx
爲什麼你想把它變成一個'do {...} while(condition)'循環?如果用戶爲「字符數」輸入零,該怎麼辦? –