We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I know this is supposed to train your if/else conditons and the task has constraints by giving you input how it wants it to but solution like this could save you unnecessary lines of code:
#include<iostream>#include<string>#include<array>intmain(){std::stringinput;std::getline(std::cin,input);intn=std::stoi(input);// Assumes valid input per problem constraintsconstexprstd::arraywords={"one","two","three","four","five","six","seven","eight","nine"};if(n>=1&&n<=9){std::cout<<words[n-1];}elseif(n>9){std::cout<<"Greater than 9";}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Conditional Statements
You are viewing a single comment's thread. Return to all comments →
I know this is supposed to train your if/else conditons and the task has constraints by giving you input how it wants it to but solution like this could save you unnecessary lines of code: