Question: This is in C++. This is a program to enter a certain amount of days then only enter the input for the days set. However

This is in C++. This is a program to enter a certain amount of days then only enter the input for the days set. However I would like it to say which day it is in front of all the outputs, and each time you enter in the temperature for a day it should print something like "Day 1" "Day 2" on separate lines.

Input example:

Enter number of days: 2

Enter temp for day 1:

Day 2:

Day 3:

Output example:

Day 1 Temp:

Day 2 temp:

Day 3 Temp:

My code:

#include #include

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::max(), ' '); 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 day: ";

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 ; //it is used to print the degree symbol in temperature value. for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!