Conditional Statements

Sort by

recency

|

862 Discussions

|

  • + 0 comments

    Kind of cheated using an array, but it's cleaner:

    // Write your code here
        if (n > 9) {
            std::cout << "Greater than 9";
        }
        else if (n >= 1){
            std::string numbers[9] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
            std::cout << numbers[--n];
        }
        return 0;
    
  • + 0 comments

    // Write your code here if(n==1) { cout<<"one"<

    return 0;
    

    }

  • + 0 comments

    int main() { string n_temp; getline(cin, n_temp);

    int n = stoi(ltrim(rtrim(n_temp)));
    
    // Write your code here
    if(n==1)
    {
        cout<<"one"<<endl;
    }
    else if (n==2) {
    cout<<"tow"<<endl;
    }
    else if (n==3) {
    cout<<"three"<<endl;
    }
    else if (n==4) {
    cout<<"four"<<endl;
    }
    else if (n==5) {
    cout<<"five"<<endl;
    }
    else if (n==6) {
    cout<<"six"<<endl;
    }
    else if (n==7) {
    cout<<"seven"<<endl;
    }
    else if (n==8) {
    cout<<"eight"<<endl;
    }
    else{
        cout<<"Greater than 9"<<endl;
    }
    
    
    return 0;
    

    }

  • + 0 comments

    if (n == 5){ cout << "five" << endl; } else if(n == 8){ cout << "eight" << endl; } else if(n > 9){ cout << "Greater than 9" << endl; } else{ cout << "error" << endl; }

  • + 0 comments

    // Write your code here n==1?cout<<"one":n==2?cout<<"two":n==3?cout<<"three":n==4?cout<<"four":n==5?cout<<"five":n==6?cout<<"six":n==7?cout<<"seven":n==8?cout<<"eight":n==9?cout<<"nine":cout<<"Greater than 9";