If anyone can help me finish this and point out what had to be done to make the program work, that would be great.
-ask for how many days user wants to enter from 1-365 (validate)
-ask for temperature for each days between -60 and 90 degrees celsius (loop, validate)
-convert each value to fahrenheit (funtion)
-output results (function)

Problem
-the users should input a int celsius number, a whole number but it converts to a double fahrenheit number
- for this code
cout << "Celsius temperature for Day " << i+1 << " : ";
*(days + 1) = GetValidInt("", TEMP_MIN, TEMP_MAX);
it outputs and waits for the input on a new line...how can i make it wait for input on the same line?

``````    #include <IOSTREAM> // input/outout stream
#include <IOMANIP>  // for setw manipulator
#include <CFLOAT>   // for limits of a double DBL_MIN and DBL_MAX
#include <CLIMITS>  // for limits of a int INT_MIN and INT_MAX

using namespace std;

//Funtion Prototypes
double GetValidDouble(string prompt = "", const double MIN = DBL_MIN, const double MAX = DBL_MAX);
int GetValidInt(string prompt = "", const int MIN = INT_MIN, const int MAX = INT_MAX);
int outputFunc (int*);
double calcCelsius(double*);
int main() {
//Constants
const int TEMP_MIN = -90;
const int TEMP_MAX = 60;
const int DAYS_MIN = 1;
const int DAYS_MAX = 365;
//Pointer
int numDays;
int *days;
//Determine the number of days to get input for
//Validation - Must be numeric || Between 1 - 365
numDays = GetValidInt("How many days do you wish to enter? ", DAYS_MIN, DAYS_MAX);

//Array Allocation
cout << "TEMPRETURE REPORTER" << endl;
cout << "====================" << endl;
cout << "Please enter the tempreture for each day." << endl;
try{
days = new int[numDays];
for(int i = 0; i < numDays; i++){
cout << "Celsius temperature for Day " << i+1 << " : ";
*(days + 1) = GetValidInt("", TEMP_MIN, TEMP_MAX);
//Validation - Between -90.00C and 60.00C
}
//for loop
for(int i = 0; i < numDays; i++){
cout << "" << outputFunc(&days);
}
//output function
delete[] days;
}
cout << "\nCould not allocate that amount memory.";
}
cout << endl << endl;
system("pause");
return 0;
}
//An inline function is a function upon which the compiler has been requested to perform inline expansion.
//In other words, the programmer has requested that the compiler insert the complete body of the function
//in every place that the function is called, rather than generating code to call the function in the one place it is defined.
inline double calcCelsius(double* celsius){
double fahrenheit = 0;
fahrenheit = (celsius*9/5)+32;
return fahrenheit;
}
//Output Fuction
int outputFunc (int* days){
double fahrenheit = 0;
//PROCESS
//double     //&days int
fahrenheit = calcCelsius(&days); //Calling calcCelsius
//OUTPUT
cout << right << setw(15) << "Day " << numDays << setw(10) << fahrenheit << char(248) << "F" << setw(10) << numDays << char(248) << "C" << endl;
}
double GetValidDouble(string prompt, const double MIN, const double MAX){
double validNumber = 0.0; // holds the user input
string rubbish;           // holds garbage input.

cout << endl << prompt << " ";
cin >> validNumber;       // try to get input
if(cin.fail()){           // if user input fails...
cin.clear();              // reset the cin object
cin >> rubbish;           // cleans garbage from cin.

// report the problem to the user.
cerr << "\nInvalid input. Please try again and enter a numeric value.\n";
// Try again by calling the function again (recursion)
validNumber = GetValidDouble(prompt, MIN, MAX);
}
else if(validNumber < MIN || validNumber > MAX){// if value is outside range...
// report the problem to the user.
cerr << "\nInvalid input. Please try again and enter a value between "
<< MIN << " and " << MAX << ".\n";
// Try again by call the function again (recursion)
validNumber = GetValidDouble(prompt, MIN, MAX);
}
return validNumber; // returns a valid value to the calling function.
}
int GetValidInt(string prompt, const int MIN, const int MAX){
double validNumber = 0.0; // holds the user input
validNumber = GetValidDouble(prompt, MIN, MAX); // get a number
if((int) validNumber < validNumber) // if the value is not a whole number...
{
cerr << "\nInvalid input. Please try again and enter a whole number.\n";
// Try again by calling the function again (recursion)
validNumber = GetValidInt(prompt, MIN, MAX);
}
return (int) validNumber; // returns a valid value to the calling function.
}
``````

it outputs and waits for the input on a new line...how can i make it wait for input on the same line?

Try not putting endl or newline char at end of the cout statement.

If that doesn't do it, then indicate where in the code the problem is found.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.