Topic link
Title description
Program to input two integers a, b,
output one when a+b=1, output
two when
a+b=2, output three when
a+b=3, output four when a+b=4, and output four,
a+b =5, output five,
a+b=6, output six,
a+b=7, output seven,
a+b=8, output eight,
a+b=9, output nine, otherwise output None (hint: switch statement )
Input
input two integers a, b, separated by a space,
Output
output the corresponding word
Sample Input
3 5
Sample Output
eight
Ideas
Operate according to the topic, either by writing a switch statement or an if-else statement.
C++ code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
while(cin >> a >> b)
{
if(a + b == 1) cout << "one" << endl;
else if(a + b == 2) cout << "two" << endl;
else if(a + b == 3) cout << "three" << endl;
else if(a + b == 4) cout << "four" << endl;
else if(a + b == 5) cout << "five" << endl;
else if(a + b == 6) cout << "six" << endl;
else if(a + b == 7) cout << "seven" << endl;
else if(a + b == 8) cout << "eight" << endl;
else if(a + b == 9) cout << "nine" << endl;
else cout << "None" << endl;
}
return 0;
}