掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
数値でなければ〜はどうすれば? (ID:69420)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
今計算機で勉強中です。 数値以外のものを入れると変なことになってしまうので、数値以外のものを入れると注意が入るようにしたいのですが、どうすればいいでしょうか。 今こんな感じです // // testing... // #include <iostream> using namespace std; int main(void) { /* trying to show testing hello world! */ cout << "testing\n"; cout << "hello world!\n"; /* trying to declarate x and y */ int x, y; /* asking what numbers are x and y */ cout << "enter the number for x (only integer, though!!): "; cin >> x; /* if x was not a number, show please enter the number */ if (x == ) cout << "enter the number for y (only integer, though!!): "; cin >> y; /* x + y = ???,,, */ cout << "x + y = " << x + y << ",,,\n"; /* this time, I should better challenge to calculate decimal number. */ /* trying to declarate a and b */ double a, b; /* asking what numbers are a and b */ cout << "enter the number for a : "; cin >> a; cout << "enter the number for b : "; cin >> b; /* a + b = ??? a - b = ??? a * b = ??? a / b = ??? */ cout << "a + b = "<< a + b << "\n"; cout << "a - b = "<< a - b << "\n"; cout << "a * b = "<< a * b << "\n"; cout << "a / b = "<< a / b << "\n"; return (0) ; }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.