Mega Code Archive

 
Categories / C++ Tutorial / Operators Statements
 

Using the conditional operator to select output

#include <iostream> using std::cin; using std::cout; using std::endl; int main() {   int mice = 1;   cout << "You have "        << mice        << (mice == 1 ? " mouse " : " mice ")        << "in total."        << endl;   return 0; } You have 1 mouse in total.