そこで、口座の残高を計算するようにこのプログラムを設定しようとしています。開始残高が正の数値として入力されていることを確認する必要があります。正の部分を削除しましたが、入力も数字であり、文字やその他の非数字ではないことを確認するにはどうすればよいですか?
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
double startBal, // Starting balance of the savings account
ratePercent, // Annual percentage interest rate on account
rateAnnual, // Annual decimal interest rate on account
rateMonth, // Monthly decimal interest rate on account
deposit1, // First month's deposits
deposit2, // Second month's deposits
deposit3, // Third month's deposits
interest1, // Interest earned after first month
interest2, // Interest earned after second month
interest3, // Interest earned after third month
count; // Count the iterations
// Get the starting balance for the account.
cout << "What is the starting balance of the account?" << endl;
cin >> startBal;
while (startBal < 0 ) {
cout << "Input must be a positive number. Please enter a valid number." << endl;
cin >> startBal;
}
// Get the annual percentage rate.
cout << "What is the annual interest rate in percentage form?" << endl;
cin >> ratePercent;
// Calculate the annual decimal rate for the account.
rateAnnual = ratePercent / 100;
// Calculate the monthly decimal rate for the account.
rateMonth = rateAnnual / 12;
while (count = 1; count <= 3; count++)
{
}
return 0;
}
ありがとう!!!