Question: This is in C++. It is supposed to let the user enter temperatures over the amount of days within an array. I keep getting an
This is in C++. It is supposed to let the user enter temperatures over the amount of days within an array. I keep getting an error on the ignore statement.what would be the correct code?
using namespace std;
double convertTemp(double celTemp);
void displayTemp(double *tmp,int size);
int main()
{
double * temp = NULL,cel;
int numberOfDays;
x:
cout << "Enter the number of days: ";
cin >> numberOfDays;
while (!cin)
{
cin.clear();
cin.ignore(numeric_limits
cout << "Enter numeric value: ";
cin >> numberOfDays;
}
if (numberOfDays < 1 || numberOfDays>365)
goto x;
try
{
//allocate dynamic memory
temp = new double[numberOfDays];
cout << "Enter temperature in Celsius: ";
for (int i = 0; i < numberOfDays; i++)
{
cin >> cel;
while (!(cel >= -90 && cel <= 60))
{
cout << "Enter valid temperature: " << endl;
cin >> cel;
}
*(temp + i)=cel;
}
//output the temperature
displayTemp(temp,numberOfDays);
}
catch (std::bad_alloc& ba)
{
std::cerr << "Error allocating memory.... " << ba.what() << ' ';
throw;
}
//delete the entire array
delete[] temp;
//to hold the output screen
system("pause");
return 0;
}
double convertTemp(double celTemp)
{
return ((9 * celTemp) / 5) + 32;
}
void displayTemp(double *tmp,int size)
{
char degree =248 ;
for(int i=0;i { cout << *(tmp+i) << degree<<"F "; int temp = convertTemp(*(tmp+i)); cout << temp << degree << "C " << endl;; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
