Plus Minus

  • + 0 comments

    my c++ solution showing the solution code only

    *
     * Complete the 'plusMinus' function below.
     *
     * The function accepts INTEGER_ARRAY arr as parameter.
     */
    
    void plusMinus(vector<int> arr) {
    int negCount{0},zeroCount{0},posCount{0};
     for (int number : arr ){
        number >0? posCount++:number<0?negCount++:zeroCount++;
     }
     double negRatio  = static_cast<double>(negCount)/arr.size();
     double posRatio  = static_cast<double>(posCount)/arr.size();
     double zeroRatio = static_cast<double>(zeroCount)/arr.size();
     cout<<std::fixed<<setprecision(6);
     cout << posRatio<<"\n"<<negRatio<<"\n"<<zeroRatio<<endl;
    
    }