Conditional Statements

Sort by

recency

|

849 Discussions

|

  • + 0 comments
    ``
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main() {
    
    
    	string numbers[] = {"one", "two", "three", "four", "five","six", "seven", "eight", "nine"};
    	string over_respond = "Greater than 9";
    
    	int n;
    	
    	scanf("%d", &n);
    
    	if ((n >= 1)&&(n <= 9)) {
    		
    		cout << numbers[n-1] << endl;
    
    	} else if (n > 9) {
    		cout << over_respond << endl;
    	}
    
    
    
    /*  TODO
     *
     *
     * n is a positive integer
     * 1 < n < 9, there is response
     * n > 9, there is over response
     *
     *
     *
     */
    `
    
    
    
    
    }
    

    `

  • + 0 comments

    int main() { // Write your code here

       int n;
    cin >> n;
    string name[] = {"For 0- Index", "one" , "two", "three" , "four", "five", "six", "seven", "eight", "nine"};
    
    if (n >= 1 and n <= 9) {
        cout << name[n];
    }
    else if (n > 9) {
        cout << "Greater than 9";
                }
    
    }
    return 0;
    

    }

  • + 0 comments

    include

    using namespace std;

    string ltrim(const string &); string rtrim(const string &);

    int main() {

    // Write your code here
    
        int n;
        cin >> n;
        if (n > 9)
        cout << "Greater than 9";
    else if (n == 1)
        cout << "one";
    else if (n == 2)
        cout << "two";
    else if (n == 3)
        cout << "three";
    else if (n == 4)
        cout << "four";
    else if (n == 5)
        cout << "five";
    else if (n == 6)
        cout << "six";
    else if (n == 7)
        cout << "seven";
    else if (n == 8)
        cout << "eight";
    else
        cout << "nine";
    
    return 0;
    

    }

  • + 0 comments
    #include <iostream>
    using namespace std;
    
    int main() {
        int a;
        cin >> a;
        string name[] = {"0" , "one" , "two", "three" , "four", "five", "six", "seven", "eight", "nine"};
        if (a >= 1 and a <= 9) {
            cout << name[a];
        }
        else if (a > 9) {
            cout << "Greater than 9";
        }
        return 0;
    }
    
  • + 0 comments

    include

    using namespace std;

    string ltrim(const string &); string rtrim(const string &);

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

    int n = stoi(ltrim(rtrim(n_temp)));
    
    // Write your code here
    cout<<"Converted numner"<<n<<endl;
    
    return 0;
    

    }

    string ltrim(const string &str) { string s(str);

    s.erase(
        s.begin(),
        find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
    );
    
    return s;
    

    }

    string rtrim(const string &str) { string s(str);

    s.erase(
        find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
        s.end()
    ); // can anyone solve this 
    
    
    return s;
    

    }