Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do i make it so it prints it just like this picture Picture click here I want it to print from smallest to greatest etc and also when we print it should be sroted small to large number.

C++
<pre>#include <iostream>
#include "MyConsoleInput.h"	// for ReadInteger, ReadDouble

using namespace ConsoleInput;
using namespace std;


//temperature convert function
double temperatureConversion(double temperature)
{
	//convert the temperature
	double converted = temperature*(9/5)+32;
}

//output function
void output(double *farenheitArray, double *dynamicTempArray, int dayAmount)
{
	cout << "DAILY TEMPERATURE REPORT" << endl << "========================" << endl << endl;

	for(int counter = 0; counter <= dayAmount; counter++)
	{
		cout << "Day  " << counter++ << farenheitArray[counter] << "�F        " << dynamicTempArray[counter] << "�C";
	}
}

int main(int argc, char** argv)
{

	//initialize the dynamic array
	double *dynamicTempArray = NULL;



	//prompt the user for an input
	cout << "How many days do you want to enter?";

	//get the user's input for the array amount
	int dayAmount = ReadInteger(1, 365);

	try
	{
		//find heap space
		//set the array to the size of the user's choosing
		dynamicTempArray = new double[dayAmount];

		//for how many days starting at 0 read data into the array
		for (int counter = 0; counter <= dayAmount; counter++)
		{
			//create the variable and enter data into
			double userInput = ReadInteger(-90.0, 60.0);



			//set the current space in the array to the user input
			dynamicTempArray[counter] = userInput;
		}

		//create an array to hold the farenheit converted temperature
		double farenheitArray[dayAmount] = {NULL};


		//for each of the inputs call the temperature conversion function
		for(int counter = 0; counter <= dayAmount; counter++)
		{
			//convert the cuttent position in the array to the farenheit
			double farenheit = temperatureConversion(dynamicTempArray[counter]);

			//set the spot in the array to the fonverted temperature
			farenheitArray[counter] = farenheit;

			//if the counter is the day amount run the output function
			if (counter == dayAmount)
			{
				cout << farenheit << " ";
			}
		}

		//done with the array, set the memory free
		delete[] dynamicTempArray;
	}
	catch(bad_alloc & ex)
	{
		cout << "Error allocating memory" << endl;
	}

	return 0;
}


What I have tried:

I haven't try cause I'm new to c++ so i have no clue how to do it
Posted
Updated 17-Mar-19 11:22am

1 solution

Do yopu really need to use arrays (and new)?
Try
C++
#include <vector>
#include <algorithm>
using namespace std;

struct Temperature
{
  Temperature(int day, double celsius):day(day),celsius(celsius){}
  int day;
  double celsius;
};

double farenh(double celsius){return celsius*9/5+32;}

ostream & operator << (ostream & os, const Temperature & t)
{
  os << "day " << t.day <<  " " << t.celsius << "°C " << farenh(t.celsius) << "°F";
  return os;
}

int main()
{
  vector <Temperature> vt;
  cout << "How many days do you want to enter?\n";
  size_t days;
  cin >> days;
  for ( size_t day = 0; day<days; ++day)
  {
    double celsius;
    cout << "Please inserte temperature (°C) of day " << (day+1) << "\n";
    cin >> celsius;
    vt.emplace_back( (day+1), celsius);
  }
  sort(vt.begin(), vt.end(), [](const Temperature & t1, const Temperature & t2) { return t1.celsius < t2.celsius;});

  for (const auto &  t : vt)
    cout << t << "\n";

}
 
Share this answer
 
Comments
Maciej Los 17-Mar-19 17:30pm    
5ed!
CPallini 17-Mar-19 17:31pm    
Thank you, Maciej!
Member 14185605 20-Mar-19 21:14pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900