Advertisement
Guest User

average using set precision and static_cast<float>

a guest
Jan 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. //This program will find the average of three test scores
  2.  
  3. #include <iostream>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. cout << fixed << setprecision(1);
  11. int num1, num2, num3;
  12.  
  13.  
  14. cout << "Please enter 3 digits: \n";
  15. cin >> num1 >> num2 >> num3;
  16. float newNum = static_cast<float>(num1 +num2+num3)/3;
  17. cout << fixed << setprecision(1);
  18. cout << "The average is: " << newNum;
  19.  
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement