Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ Language, I need help to get output in 2 decimals places. This works put

ID: 3723457 • Letter: I

Question

In C++ Language, I need help to get output in 2 decimals places. This works put the decimal places are missing. How do I get 2 decimals place in ?

void printResults(alphabetCountType letters[], ofstream &out, int counts){
  
    // header in the file
    out << "Letter Number Percentage";
    cout << counts;
  

    // print the data in the file
    for (int i = 0; i < NO_LETTERS_IN_ALPHABET; i++){
     
   
        out << " " << static_cast<char>(i+65)
            << "      " << letters[i].capitalCount
            << setw(9)<< right
            << setprecision(5) << fixed
            << (letters[i].capitalCount *100)/counts << "%";
          
          
        out << " " << static_cast<char>(i+97)
            << "      "<< letters[i].lowerCaseCount
            << setw(9)<< right
            << setprecision(5) << fixed << showpoint
            << (letters[i].lowerCaseCount *100)/counts << "%";  
                  
    }; // end of for loop  
  
    cout << " Printed results to the output file";  
  
} // end of print results function

Explanation / Answer

Note : could yoi plz check this code by inclusing the header file in the program ..

_____________

we haver to include the headef file

#include <iomanip> // std::setprecision

_______________

void printResults(alphabetCountType letters[], ofstream &out, int counts){
  
    // header in the file
    out << "Letter Number Percentage";
    cout << counts;
  

    // print the data in the file
    for (int i = 0; i < NO_LETTERS_IN_ALPHABET; i++){
     
   
        out << " " << static_cast<char>(i+65)
            << "      " << letters[i].capitalCount
            << setw(9)<< right
            << setprecision(2) << fixed
            <<((double)(letters[i].capitalCount *100))/counts << "%";
          
          
        out << " " << static_cast<char>(i+97)
            << "      "<< letters[i].lowerCaseCount
            << setw(9)<< right
            << setprecision(2) << fixed << showpoint
            << ((double)(letters[i].lowerCaseCount *100))/counts << "%";  
                  
    }; // end of for loop  
  
    cout << " Printed results to the output file";  
  
} // end of print results function

______________Thank You