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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started