Talk About Network

Google





Programming > C - C++ Learning > Arithmetic with...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4093 of 4400
Post > Topic >>

Arithmetic with char and long

by fermineutron <free4trample@[EMAIL PROTECTED] > Apr 3, 2008 at 04:32 PM

I ran into a cast type problem which i do not quite know how to
approach, please help.

I have a float variable s initialized to 0. in a loop i use following
code:
s=s+(float)score[tmp1];

score is a char array. this array contains numbers 1-5.
it seems that every time loop executes s is increased by about 50,
increases range from 48 to 53 ish.
 without the cast i get exactly same behavior.
I can verify that values in s are ranging from 1 to 5 with print
statement using %c in the print.

Full loop is below, score is a global variable.

================start paste==================
while(i1<ML[movie][1]){


			weight=weight+1;
			tmp1=i1+ML[movie][0];
		s=s+(float)score[tmp1];
		printf("score in loop is: %c",score[tmp1]);
		printf("s is: %f\n",s);
			i2++;

		i1++;
	}

================end paste=================

sorry cant post full code, its rather long and to run requires a
rather large pre-formatted dataset in same dir.

Thanks ahead for ur help.
 




 4 Posts in Topic:
Arithmetic with char and long
fermineutron <free4tra  2008-04-03 16:32:23 
Re: Arithmetic with char and long
"Alf P. Steinbach&qu  2008-04-04 01:41:27 
Re: Arithmetic with char and long
Ron Natalie <ron@[EMAI  2008-04-03 19:41:45 
Re: Arithmetic with char and long
fermineutron <free4tra  2008-04-03 16:47:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 11:54:28 PST 2009.