basic

C++基本中の基本その8

※自分用メモ ※引用元「ローベルのC++入門講座」 #include <iostream> #include <string> using namespace std; void obamaTerm(int &x) //int &xを変数にすることで「参照」という変数が作れる。 { if(2009 <= x && x <= 2016) x -= 2008; else x = 0; } void presidency() //</string></iostream>…

C++基本中の基本その6

※自分用メモ ※引用元「ローベルのC++入門講座」 【ループ】 同じ処理を何度も行いたい場合にはfor文を使う。 for文: for(int i = 0; i < 処理の回数; i++) {実行分} ってことで。。。 #include <iostream> #include <string> using namespace std; int main() { for(int i = 0;</string></iostream>…

C++基本中の基本その5

※自分用メモ ※引用元「ローベルのC++入門講座」 【条件分岐その2】 ・if 文は変数などがある値をとったときの処理を決める。 ・変数や関数の戻り値などがある値をとったときの処理を決める。 #include <iostream> #include <string> using namespace std; void divide() { int </string></iostream>…

C++基本中の基本その4

※自分用メモ ※引用元「ローベルのC++入門講座」 【条件分岐】 ・条件分岐の書式は if(<条件>){ <実行文1> } else{ <実行文2> } ・else 文はなくてもよい ・<条件>用の演算子がある #include <iostream> using namespace std; void age() { int x; cout << "How old a</iostream>…

C++基本中の基本その3

※自分用メモ ※引用元「ローベルのC++入門講座」 【入力】 cin >> variableでプログラムへと値を入力する。 #include <iostream> using namespace std; int main() { int a; cout << "your number is: " << flush; cin >> a; cout << "the total of "your number" and 1</iostream>…

C++の基本中の基本その2

※自分用メモ ※引用元「ローベルのC++入門講座」 【void型】 関数には引数を持ったり、戻り値のない関数もあります。 以下のプログラム: #include <iostream> using namespace std; int add(int x, int y) { return x + y; } int main() { cout << "add(3, 4) = " << a</iostream>…

C++の基本中の基本

※自分用メモ ※引用元「ローベルのC++入門講座」 【文字を表示させる】 誰もが通るであろう一番初めに習うプログラムの定番: Hello Worldを表示させるには。。。 #include <iostream> using namespace std; int main() { cout << "Hello World" << endl; } このうち文</iostream>…