You are viewing a single comment's thread. Return to all comments →
Using Key Value pairs with OR gate condition,
int main(){ map numbers; int a ; cin >> a ; numbers[1] = "one"; numbers[2] = "two"; numbers[3] = "three"; numbers[4] = "four"; numbers[5] = "five"; numbers[6] = "six"; numbers[7] = "seven"; numbers[8] = "eight"; numbers[9] = "nine"; if (numbers.find(a) != numbers.end()){ cout << numbers[a]; } else if ((numbers.find(a) == numbers.end()) || (a > 9) ) { cout << "Greater than 9"; } }
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 →
EASY SOLUTION works 100%
Using Key Value pairs with OR gate condition,
int main(){ map numbers; int a ; cin >> a ; numbers[1] = "one"; numbers[2] = "two"; numbers[3] = "three"; numbers[4] = "four"; numbers[5] = "five"; numbers[6] = "six"; numbers[7] = "seven"; numbers[8] = "eight"; numbers[9] = "nine"; if (numbers.find(a) != numbers.end()){ cout << numbers[a];
}
else if ((numbers.find(a) == numbers.end()) || (a > 9) ) { cout << "Greater than 9"; }
}