它非常简单,因为你放了多次显示数字 cout << "Invalid value input " ; 在循环内。如果你把它放在循环之前它只会显示一次。
cout << "Invalid value input " ;
cout << " Enter a non negative number greater than 0: "; cin >> c0; if (c0 <= 0) { cout << "Invalid value input " ; } while (c0 != 1) { ... }
接下来要考虑的是当用户输入无效数字时您想要发生的事情。你想中止这个节目吗?您想再次询问用户吗?目前该计划将继续进行,好像什么都没发生过一样。