[問題]C++數字該如何比較大小
以下是小弟的程式碼
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
int main()
{
int count=1;
int number;
int largest;
while (count<=10)
{
cout<<"please enter the number: ";
cin>>number;
number=largest;
if (number>largest)
largest=number;
count=count+1;
}
cout<<"the largest number is:"<<largest;
system("pause");
return 0;
}
可是最後出來的largest卻一直是我最後輸入的數字
該怎麼樣才能讓最大的數字是largest呢?
謝謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.114.96.134
推
01/01 23:55, , 1F
01/01 23:55, 1F
→
01/01 23:55, , 2F
01/01 23:55, 2F
→
01/01 23:57, , 3F
01/01 23:57, 3F
→
01/02 00:03, , 4F
01/02 00:03, 4F
→
01/02 00:16, , 5F
01/02 00:16, 5F
→
01/02 00:19, , 6F
01/02 00:19, 6F
→
01/02 00:24, , 7F
01/02 00:24, 7F
推
01/02 00:28, , 8F
01/02 00:28, 8F
推
01/02 01:37, , 9F
01/02 01:37, 9F
噓
01/02 10:30, , 10F
01/02 10:30, 10F
→
01/02 10:31, , 11F
01/02 10:31, 11F
→
01/02 10:31, , 12F
01/02 10:31, 12F
→
01/03 14:16, , 13F
01/03 14:16, 13F