Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   conversion program (http://www.go4expert.com/forums/conversion-program-t16218/)

chemr3 17Feb2009 03:52

conversion program
 
Hello all. I have been trying to write a program that converts degrees fahrenheit to celsius.
The way I have the program written now when you hit run it will just calculate conversions up to the max_fahrenheit = 100. I want to be able to ask the person using the program to enter the number of conversions they want to see. I have put a text block around the code that asks for input below. I need to figure out how to take that input and give the user back the number of conversions they want. Any help would be greatly appreciated.
Code:

#include<iostream>
#include<iomanip>
using namespace std;
 
int main()
{
    double celsius;
    int fahrenheit;
    const int far_value = 20;
    const int far_step = 4;
    int max_fahrenheit=100;
    int conversions;
 
    cout<<"This program is designed to convert values from fahrenheit to celsius\n"<<endl;
 
/*cout<<"Please enter the number of conversions\n"<<endl;
    cin>>conversions;
*/
 
 
    fahrenheit = far_value;
 
    cout<< setiosflags(ios::showpoint)
        << setprecision(2);
 
    cout<< "\n Degrees      Degrees\n"
        << "Fahrenheit    Celsius\n\n"; 
 
    while (fahrenheit <= max_fahrenheit)
    {
 
 
          celsius =  (fahrenheit - 32.0) / (9.0/5.0);
 
          cout<< setw(5) << fahrenheit << fixed
              << setw(15)<< celsius << endl;
 
 
          fahrenheit = (fahrenheit + far_step);
 
 
    }
 
      system("pause");
      return 0;
}


xpi0t0s 17Feb2009 04:03

Re: conversion program
 
Put a for loop around the code you want to repeat:
Code:

cin<num_conversions;
for (int i=0; i<num_conversions; i++)
{
  // the code you want to repeat
}


chemr2 17Feb2009 06:51

Re: conversion program
 
Quote:

Originally Posted by xpi0t0s (Post 42996)
Put a for loop around the code you want to repeat:
Code:

cin<num_conversions;
for (int i=0; i<num_conversions; i++)
{
  // the code you want to repeat
}


Thanks so much


All times are GMT +5.5. The time now is 10:35.