I was told that I could compact this code in 2 ways. I can't use loops. Can anyone see it?

#include <iostream>
#include <string>
using namespace std;
void daysOfChristmas (int days, char switcher, string b[12]){
    (days > 0 && switcher == 'y') ? daysOfChristmas(days - 1, 'y', b): false; 
    (days > 0) ? daysOfChristmas(days - 1, 'n', b): false;
    cout << "on the " << days << " day of Christmas my true love gave me " << b[(days-1)] << endl;
int main() {
    string gifts [12] = {"a partridge in a Pear Tree", "two turtle doves", "three french hens", "four colly birds", "five golden rings", "six gees-a-laying", "seven swans-a-swimming", "eight maids a miliking", "nine ladies dancing", "ten lords a leaping", "eleven pipiers piping", "drummers drumming"};
    daysOfChristmas(12, 'y', gifts);}

Edited by Reverend Jim: Fixed formatting

6 Years
Discussion Span
Last Post by sfuo

Welcome to DaniWeb. To help us help you most effectively, please use a descriptive thread title. Please also use code tags when you post code.

It looks pretty "compact" (aka hard to read!) already to me!



I switched made the function return a bool because you are returning false on a void function and ran it and it "broke" and made my motherboard speaker go off like a christmas song for like 3 min.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.