Conditional Statements

Sort by

recency

|

853 Discussions

|

  • + 0 comments
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        long long n=0;
        cin>>n;
        string number[]={"one","two","three","four","five","six","seven","eight","nine"};
        if (n<=9){cout<<number[n-1];} else cout<<"Greater than 9";
    }
    
  • + 0 comments
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        long long n=0;
        cin>>n;
        //this shit is too ugly nigga
        // 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 if(n==9) {cout<<"nine";}
        // return 0;
        string number[]={"one","two","three","four","five","six","seven","eight","nine"};
        if (n<=9){cout<<number[n-1];} else cout<<"Greater than 9";
    }
    
  • + 0 comments
    #include <iostream>
    using namespace std;
    
    int main() {
      int n;
      cout << "Pick any number: "; //Optional
      cin >> n;
    
      string num[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
      int size = sizeof(num) / sizeof(num[0]);
      for (int i = 0; i < size; i++) {
        if (n > 9) {
          cout << "Greater than 9" << endl;
          break;
        } else if (n == i) {
          cout << num[n-1] << endl;
          break;
        } else {
          continue;
        }
      }
      return 0;
    }
    
  • + 0 comments

    include

    include

    using namespace std;

    int main() { int x; cin >> x; string kq =(x==1)? "one" : (x==2)? "two" : (x==3)? "three" : (x==4)? "four" : (x==5)? "five" : (x==6)? "six" : (x==7)? "seven" : (x==8)? "eight" : (x==9)? "nine" : "Greater than 9"; cout << kq << endl; }

  • + 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
     *
     *
     *
     */
    `
    
    
    
    
    }
    

    `