Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- double speed;
- cin >> speed;
- string info = "";
- if (speed <= 10) {
- info = "slow";
- }
- else if (speed <= 50) {
- info = "average";
- }
- else if (speed <= 150) {
- info = "fast";
- }
- else if (speed <= 1000) {
- info = "ultra fast";
- }
- else if (speed > 1000) {
- info = "extremely fast";
- }
- cout << info << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- double speed;
- cin >> speed;
- string info =
- speed <= 10 ? "slow" :
- speed <= 50 ? "average" :
- speed <= 150 ? "fast" :
- speed <= 1000 ? "ultra fast" : "extremely fast";
- cout << info << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement