Hi, how do I get rid of a conversion from double to float warning??

Thanks

typecast it

float n = 123.45F;

double x = (double)n;

or
double x = static_cast<double>(n);

hi thanks, I tried that but I'm obviously not implimenting it properly. I'll go back and maybe create another variable to see if that fixes my problem....otherwise I'll post. I know I have to type cast, I just don't understand the logic yet, so struggling a bit...BRB.

:)

// RandLink.cpp : main project file.

#include "stdafx.h"
#include "bubble.h"
#include <list>
#include <iostream>
#include <time.h>

using namespace System;
using namespace std;

	
int main(array<System::String ^> ^args)
{
    double sum = 0;
	int count = 0;
	float average = 0;
	
	int Iarray[25];
	srand( (unsigned)time( NULL ) );
	for (int i=0;i<25;i++)
	{
		int number = rand() % 100;
		Iarray[i] = number;
	}
 
		list<int> randLink;
		randLink.assign(Iarray, Iarray + 25);
		cout << "contents of list are: " << ' ' << endl;

		list<int>::iterator p;
		for (p = randLink.begin(); p != randLink.end(); p++)
		cout << *p << endl;
		randLink.sort();
		cout<< "after the sort function the contents are: "<< endl;
		for (p = randLink.begin(); p != randLink.end(); p++)
		cout << *p << endl;

		for (p = randLink.begin(); p != randLink.end(); p++)
		{
			sum = sum + *p;
			count = count + 1;
		}
			average = static_cast<double>(sum/count);
		//average = sum/count;
		//double sum = double average;
			cout <<"The sum is equal to:  " << sum << endl;
			cout <<"The average is equal to:  " << average << endl;

}

Can you please help me to understand? Thanks

:-) okay, I got it, thanks for the help.

// RandLink.cpp : main project file.

#include "stdafx.h"
#include "bubble.h"
#include <list>
#include <iostream>
#include <time.h>

using namespace System;
using namespace std;

	
int main(array<System::String ^> ^args)
{

	
	int Iarray[25];
	srand( (unsigned)time( NULL ) );
	for (int i=0;i<25;i++)
	{
		int number = rand() % 100;
		Iarray[i] = number;
	}
 
		list<int> randLink;
		randLink.assign(Iarray, Iarray + 25);
		cout << "contents of list are: " << ' ' << endl;

		list<int>::iterator p;
		for (p = randLink.begin(); p != randLink.end(); p++)
		cout << *p << endl;
		randLink.sort();
		cout<< "after the sort function the contents are: "<< endl;
		for (p = randLink.begin(); p != randLink.end(); p++)
		cout << *p << endl;

		double sum = 0;
		int count = 0;
		float average = 0.00;
		

		for (p = randLink.begin(); p != randLink.end(); p++)
		{
			sum = sum + *p;
			count = count + 1;
		}
		average = static_cast<float>(sum/count);
		//average = sum/count;
		//double sum = double average;
		cout <<"The sum is equal to:  " << sum << endl;
		cout <<"The average is equal to:  " << average << endl;

}
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.