GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Feb-2006, 07:10
donaldk donaldk is offline
New Member
 
Join Date: Feb 2006
Posts: 2
donaldk is on a distinguished road

conversion double to float


warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(261) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(270) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(280) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(28 : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(29 : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(304) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

I need help badly. I can compile my program but is warning have stop me from get the program to run well. Can someone guide me along and what possible error do i have. thanks
  #2  
Old 11-Feb-2006, 07:14
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: conversion double to float


Hello and Welcome to GIDForums™ donaldk. Please read the Sticky that gives some good guidelines for posting. Without any code, it is not likely you will get much help.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #3  
Old 11-Feb-2006, 08:17
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: conversion double to float


Quote:
Originally Posted by donaldk
warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
e:\ap power\project4.cpp(261) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
warning have stop me from get the program to run well.

These are warnings, not errors. Look at the lines that were flagged. Was there some assignment to a variable of type float? Was there a function call where a parameter was of type float? What?

Since "doubles" have more precision than "floats", assignment of an expression that has type "double" to a variable or function parameter that has type "float" will give this message with (some) C++ compilers. Note that floating point literals, such as 3.3 are treated by compilers as "doubles". If you want to make sure the compiler treates it as a "float", then use 3.3f in expressions.

No one can here tell you whether the items flagged by these messages cause your program not to "run well", since no one here has seen your code. In fact, we don't have any way of knowing what you mean by not running well. What exactly happens when you attempt to run your program?

You might get rid of the messages by changing your variables from "floats" to "doubles" (if the program specification allows that). If you have variables, x and y of type "float", and you have something like x = y / 3.0;, you could either change the declarations of x and y to make them "doubles" or you could change the assgnment statement to x = y / 3.0f.


Regards,

Dave
  #4  
Old 12-Feb-2006, 22:16
donaldk donaldk is offline
New Member
 
Join Date: Feb 2006
Posts: 2
donaldk is on a distinguished road

Analysis the function for charges


Hi, thanks for the guiding and help. However, i need to help to analysis the program of the car parking. This program allow user to key in "Entry point X to the car park and Exit point A or Exit point B from the car park.It also allow user the key in the entry time and exit time.
It is the charges of the park slots that confuse me. I need help in analysis the last past of the function.

void amount(struct transaction inf[],int h)

For peak hours, 7am to 5.59pm, the parking charge for the car parking is $1.00 per half-hour. For non-peak hours, 6pm to 6.59am, the parking charge is $0.50 per half-hour. The parking is always calculated to the nearest half-hour
Below is the program.

CPP / C++ / C Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define MAX 5

struct vehicle{
	int vehi_no;
	float timein;
};
struct transaction{
	struct vehicle data;
	char exit_point[1];
	float timeout;
	float amount;
};
void toupperC(char *con);
int entry(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*i);
int outA(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*waitb);
int outB(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*waitb);
void amount(struct transaction inf[],int h);
void vehiF(struct transaction inf[],int j);
void printfile(struct transaction inf[],int h);
main()
{
	printf("The carpark is empty at initial.\n");
	int a,b,c,d,e;   //carlot status
	a=b=c=d=e=0;
	int waita,waitb;	//condition of whether car is waiting.
	waita=waitb=0;
	int i,j; //num of carlots free.
	i=0;
	int num;
	char condition[20];
	struct transaction info[MAX+5];
	while(i!=100000)  //for ever loop.
	{
  		if(waita==1 && waitb==1)
		{
			waita=waitb=0;
			printf("There is a vancant carlot,pls proceed.\n");
			j=entry(info,&a,&b,&c,&d,&e,&i);
			vehiF(info,j);
		}
		printf("Please enter car in or out : ");
		fflush(stdin);
		gets(condition);
		toupperC(condition);
		if(strcmp(condition,"ENTRY POINT X")==0)
		{
			if(i==5)
			{
				printf("Carpark is full.pls wait\n\n");
				waita=1;
			}
			else
			{
				j=entry(info,&a,&b,&c,&d,&e,&i);
				vehiF(info,j);
			}
		}
		else if((strcmp(condition,"EXIT POINT A")==0) || (strcmp(condition,"EXIT POINT B")==0))
		{
			if(i==0)
			{
				printf("There is no car in the carpark.\nPlease don't play a fool.\n\n");
			}
			else if(strcmp(condition,"EXIT POINT A")==0)
			{
				i=i-1;
				num=outA(info,&a,&b,&c,&d,&e,&waitb);
				amount(info,num);
				printfile(info,num);
			}
			else if(strcmp(condition,"EXIT POINT B")==0)
			{
				i=i-1;
				num=outB(info,&a,&b,&c,&d,&e,&waitb);
				amount(info,num);
				printfile(info,num);
			}
		}
		else
			printf("Invalid Input.\nPlease enter again.\n\n");
	}
	return 0;
}
void toupperC(char *con)
{
	char *ptr;
	ptr=con;
	while(*ptr !='\0')
	{
		if(isalpha(*ptr))
		{
			*ptr=toupper(*ptr);
			ptr++;
		}
		else
			ptr++;
	}
	return;
}
int entry(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*i)
{
	int f=0;

	if(*a==0)
	{
		*a=1;
		f=0;
	}
	else if(*b==0)
	{
		*b=1;
		f=1;
	}
	else if(*c==0)
	{
		*c=1;
		f=2;

	}
	else if(*d==0)
	{
		*d=1;
		f=3;
	}
	else if(*e==0)
	{
		*e=1;
		f=4;
	}
	(*i)++;
	printf("Please enter the 4-digit vehicle number : ");
	scanf("%d",&inf[f].data.vehi_no);
	//fflush(stdin);
	//gets(inf[f].data.vehi_no);
	printf("Please enter time of entry in '24.00' hr format : ");
	scanf("%f",&inf[f].data.timein);
	printf("Time enter into carpark is %.2f\n",inf[f].data.timein);
	printf("Please proceed to carlot number %d.\n",f+1);
	printf("The Barrier is lifted.\n");
	printf("The Barrier is closed.\n\n");
	return f;
}
int outA(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*waitb)
{
	*waitb=1;
	int E;
	int z=5;
	printf("Please enter your 4-digit vehicle number : ");
	scanf("%d",&E);
	while(z==5)
	{
		z=0;
		while(inf[z].data.vehi_no!=E)
		{
			z++;
			if(z>4)
			{
				z=0;
				printf("No such car.\n");
				printf("Please enter your 4-digit vehicle number again : ");
				scanf("%d",&E);
			}
		}
	}
	printf("Please enter time of exit in 24.00 hr : ");
	scanf("%f",&inf[z].timeout);
	strcpy(inf[z].exit_point,"A");
	printf("The Barrier at exit A is lifted.\n");

	switch(z)
	{
	case 0:*a=0;break;
	case 1:*b=0;break;
	case 2:*c=0;break;
	case 3:*d=0;break;
	case 4:*e=0;break;
	}
	return z;
}
int outB(struct transaction inf[],int *a,int *b,int *c,int *d,int *e,int
*waitb)
{
	*waitb=1;
	int E;
	int z=5;
	printf("Please enter your 4-digit vehicle number : ");
	scanf("%d",&E);
	while(z==5)
	{
		z=0;
		while(inf[z].data.vehi_no!=E)
		{
			z++;
			if(z>4)
			{
				z=0;
				printf("No such car.\n");
				printf("Please enter your 4-digit vehicle number again : ");
				scanf("%d",&E);
			}
		}
	}
	printf("Please enter time of exit in 24.00 hr : ");
	scanf("%f",&inf[z].timeout);
	strcpy(inf[z].exit_point,"B");
	printf("The Barrier at exit B is lifted.\n");
	switch(z)
	{
	case 0:*a=0;break;
	case 1:*b=0;break;
	case 2:*c=0;break;
	case 3:*d=0;break;
	case 4:*e=0;break;
	}
	return z;
}
[b][color="Red"]void amount(struct transaction inf[],int h)
{
	float g,l;
	float S1,S2,S3,S4,S5,T;
	S1=S2=S3=S4=S5=T=0;
	g=inf[h].data.timein;
	l=inf[h].timeout;
	if(0<g && g<6.59)
	{
		if(0<l && l<6.59)  // is check corrected.
		{
			if(l>g)
			{
				while((l-g)>=1)
				{
					l=l-1;
					S1++;
				}
				while(l>=1)
				{
					l--;
				}
				while(g>=1)
				{
					g--;
				}
				if(g>l)
				{
					g=0.59-g+l;
					while(g>0)
					{
						g=g-0.3;
						S3++;
					}
				}
				else
				{
					l=l-g;
					while(l>0)
					{
						l=l-0.3;
						S3++;
					}
				}
				T=S1+(S3/2);
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
			else
			{
				g=6.59-g;
				while(g>=1)
				{
					g--;
					S1++;
				}
				while(g>0.3)
				{
					g=g-0.3;
					S2++;
				}
				while(l>=1)
				{
					l--;
					S3++;
				}
				while(g>0.3)
				{
					l=l-0.3;
					S4++;
				}
				g=g+l;
				while(g>0)
				{
					g=g-0.3;
					S5++;
				}
				T=28+S1+S3+(S2+S4+S5)/2;
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
		}
		else if(7<l && l<17.59)  //is check corrected.
		{
			g=6.59-g;
			while(g>=1)
			{
				g--;
				S1++;
			}
			while(g>0)
			{
				g=g-0.3;
				S2++;
			}
			l=l-7;
			while(l>=1)
			{
				l--;
				S3++;
			}
			while(l>0)
			{
				l=l-0.3;
				S4++;
			}
			T=S1 + (S2/2) + (S3*2) + S4;
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
		else if(18<l && l<23.59)  //is checked correct.
		{
			g=6.59-g;
			while(g>1)
			{
				g--;
				S1++;
			}
			while(g>0.3)
			{
				g=g-0.3;
				S2++;
			}
			l=l-18;
			while(l>=1)
			{
				S3++;
				l--;
			}
			while(l>0.3)
			{
				S4++;
				l=l-0.3;
			}
			g=g+l;
			while(g>0)
			{
				g=g-0.3;
				S5++;
			}
			T=S1+S3+(S2+S4+S5)/2+22;
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
	}
	else if(7<g && g<17.59)
	{
		if(0<l && l<6.59)  //is checked correct.
		{
			g=17.59-g;
			while(g>=1)
			{
				S1++;
				g--;
			}
			while(g>0)
			{
				g=g-0.3;
				S2++;
			}
			while(l>=1)
			{
				S3++;
				l--;
			}
			while(l>0)
			{
				S4++;
				l=l-0.3;
			}
			T=6+(S1*2)+S2+S3+(S4/2);
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
		else if(7<l && l<17.59)  //also corrected.
		{
			if(l>g)
			{
				while((l-g)>=1)
				{
					l=l-1;
					S1++;
				}
				while(l>=1)
				{
					l--;
				}
				while(g>=1)
				{
					g--;
				}
				if(g>l)
				{
					g=0.59-g+l;
					while(g>0)
					{
						g=g-0.3;
						S2++;
					}
				}
				else
				{
					l=l-g;
					while(l>0)
					{
						l=l-0.3;
						S2++;
					}
				}
				T=(S1*2)+S2;
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
			else
			{
				g=17.59-g;
				while(g>1)
				{
					g--;
					S1++;
				}
				while(g>0.3)
				{
					g=g-0.3;
					S2++;
				}
				l=l-7;
				while(l>=1)
				{
					l--;
					S3++;
				}
				while(l>=0.3)
				{
					l=l-0.3;
					S4++;
				}
				g=g+l;
				while(g>0)
				{
					g=g-0.3;
					S5++;
				}
				T=13+(S1+S3)*2+S2+S4+S5;
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
		}
		else if(18<l && l<23.59)  // is corrected.
		{
			g=17.59-g;
			while(g>1)
			{
				g--;
				S1++;
			}
			while(g>0)
			{
				g=g-0.3;
				S2++;
			}
			l=l-18;
			while(l>=1)
			{
				l--;
				S3++;
			}
			while(l>0)
			{
				l=l-0.3;
				S4++;
			}
			T=(S1*2)+S2+S3+(S4/2);
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
	}
	else if(18<g && g<23.59)
	{
		if(0<l && l<6.59)
		{
			g=23.59-g;
			while(g>1)
			{
				g--;
				S1++;
			}
			while(g>0.3)
			{
				g=g-0.3;
				S2++;
			}
			while(l>=1)
			{
				l--;
				S3++;
			}
			while(l>0.3)
			{
				l=l-0.3;
				S4++;
			}
			g=g+l;
			while(g>0)
			{
				g=g-0.3;
				S5++;
			}
			T=S1+S3+((S4+S2+S5)/2);
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
		else if(7<l && l<17.59)
		{
			g=23.59-g;
			while(g>1)
			{
				g--;
				S1++;
			}
			while(g>0)
			{
				g=g-0.3;
				S2++;
			}
			l=l-7;
			while(l>=1)
			{
				l--;
				S3++;
			}
			while(l>0)
			{
				l=l-0.3;
				S4++;
			}
			T=7+S1+S3*2+S4+S2/2;
			inf[h].amount=T;
			printf("Please pay $%.2f\n\n",inf[h].amount);
		}
		else if(18<l && l<23,59)
		{
			if(l>g)
			{
				while((l-g)>=1)
				{
					l=l-1;
					S1++;
				}
				while(l>1)
				{
					l--;
				}
				while(g>1)
				{
					g--;
				}
				if(g>l)
				{
					g=0.59-g+l;
					while(g>0)
					{
						g=g-0.3;
						S2++;
					}
				}
				else
				{
					l=l-g;
					while(l>0)
					{
						l=l-0.3;
						S2++;
					}
				}
				T=S1+(S2/2);
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
			else
			{
				g=23.59-g;
				while(g>1)
				{
					g--;
					S1++;
				}
				while(g>0.3)
				{
					g=g-0.3;
					S2++;
				}
				l=l-18;
				while(l>=1)
				{
					l--;
					S3++;
				}
				while(l>0.3)
				{
					S4++;
					l=l-0.3;
				}
				g=g+l;
				while(g>0)
				{
					g=g-0.3;
					S5++;
				}
				T=29+S1+S3+(S2+S4+S5)/2;
				inf[h].amount=T;
				printf("Please pay $%.2f\n\n",inf[h].amount);
			}
		}
		return;
	}
}[/color][/b]void vehiF(struct transaction inf[],int j)
{
	FILE *fout;
	fout=fopen("Vehicle.txt","a");
	if(fout==NULL)
	{
		printf("Error reading file.");
		exit(1);
	}
	fprintf(fout,"Vehicle number = %d\nTime entry is %.2f\n\n",inf[j].data.vehi_no,inf[j].data.timein);
	fclose(fout);
	return;
}
void printfile(struct transaction inf[],int h)
{
	FILE *fout;
	fout=fopen("Transaction.txt","a");
	if(fout==NULL)
	{
		printf("Error reading file.");
		exit(1);
	}
	fprintf(fout,"Vehicle number = %d\nTime entry is %.2f\nTime exit is %.2f\nAmount charged is %.2f\nExited from exit %s\n\n",inf[h].data.vehi_no,inf[h].data.timein,inf[h].timeout,inf[h].amount,inf[h].exit_point);
	fclose(fout);
	inf[h].data.vehi_no=987654;
	return;
}
Last edited by LuciWiz : 27-Mar-2006 at 12:29. Reason: Please insert your C code between [c] & [/c] tags
  #5  
Old 12-Feb-2006, 22:46
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Analysis the function for charges


Quote:
Originally Posted by donaldk
Hi, thanks for the guiding and help. However, i need to help to analysis the program of the car parking.
Below is the program.

Let's see; by my rough approximation, there are about 668 lines of code and about 416 are highlighted in red.

I think there is a typographical error on line 566:
CPP / C++ / C Code:
		else if(18<l && l<23,59)

Probably should be 23.59, not 23,59

Regards,

Dave
Last edited by davekw7x : 12-Feb-2006 at 23:19.
  #6  
Old 12-Feb-2006, 23:16
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: Analysis the function for charges


Quote:
Originally Posted by davekw7x
Let's see; by my rough approximation, there are roughly 668 lines of code and about 416 are highlighted in red.
And after being asked to read the Guidelines, too. Maybe you should reread them, esp #1 and #2. #3 wouldn't hurt either.
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Canny edge detector Skm Java Forum 1 01-Jan-2006 06:51
Powell Method EngineerFORhire C Programming Language 5 01-Oct-2005 00:34
Double output leanieleanz C++ Forum 1 11-Mar-2005 20:19

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:08.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.