タイトルはおそらくわかりにくいと思われるので、最初にコードを示します。この単純なプログラムを作成して、2 つの入力値を取得し、それらを乗算します。もう 1 つのことですが、それは重要ではありません。正しく動作します。
#include <iostream>
using namespace std;
main()
{
int a,b,c,d,e;
char j = 4;
cout << "Welcome to Momentum Calculator\n\n";
cout << "------------------------------\n";
cout << "Please Enter Mass in KG (if the mass in in grams, put \"9999\" and hit enter): \n\n";
cin >> a;
if (a==9999) {
cout << "\nPlease Enter Mass in grams: \n\n";
cin >> d;
}
else {
d = 0;
}
cout << "\nPlease Enter Velocity \n\n";
cin >> e;
if (d == 0)
{
c = (a*e);
}
else {
c = (e*d)/100;
}
cout << "\nMomentum = " << c;
cin.get();
cin.ignore();
while (j == 4)
{
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
main();
}
}
ご覧のとおり、私の変数は int (整数) であり、私の問題は、英語の文字 (az) または数字以外のものを入力すると、プログラムが無制限の速度で無制限に繰り返されることです。変数「a」が文字か何かかを文字列/文字で確認したいのですが、方法がわかりません。私はそれを行うことができますが、ユーザーに「a」に1回だけ入力してもらいたいので、もう一度入力させます。助けてください :)