fork download
  1. /*
  2.  * lesson6part2.cpp
  3.  *
  4.  * Created on: Oct 15, 2017
  5.  * Author: elb170230
  6.  */
  7.  
  8. #include <iostream>
  9. #include <iomanip>
  10. using namespace std;
  11.  
  12. int main (){
  13. double startTemp, endTemp, increment, celsius; //3 values the user inputs, celsius for conversion later on.
  14. cin >> startTemp >> endTemp >> increment;
  15.  
  16. while ((startTemp >= endTemp)||(increment <= 0)){ //error message if user inputs invalid numbers
  17. cout << "Starting temperature must be <= ending temperature and increment must be > 0.0" << endl;
  18. cin >> startTemp >> endTemp >> increment; //lets user try again.
  19. }
  20. cout << setw(15) << "Fahrenheit" << setw(15) << "Celsius" << endl;
  21. while (startTemp <= endTemp){ //only continues until endTemp is reached.
  22. celsius = ((startTemp - 32)/ 1.8); //equation for conversion to celsius
  23. cout << setw(15) << setprecision(3) << fixed << startTemp << setw(15) << setprecision(3) << fixed << celsius << endl;
  24. //use setw and setprecision to format it correctly and fix numbers to 3 decimal places.
  25. startTemp = startTemp + increment;
  26. //increases startTemp by the increment input by the user so loop is not infinite.
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. return 0;
  35. }
  36.  
  37.  
  38.  
  39.  
  40.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
     Fahrenheit        Celsius
          0.000        -17.778
          0.000        -17.778