473,411 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Why the variablle's value is so weird

HI:

The code I write is :

static int numTrial;
static float perCentage;
static int gapValue;
static int inValue;
for( gapValue = inValue; gapValue <= MAX_GAP; gapValue = (gapValue +
GAP_STEP)){

for (perCentage = 0.0; perCentage <= 1.0;perCentage = (perCentage
+0.1)){

for (numTrial = 0; numTrial < 5 ; numTrial ++){

Send packet sequence to the End Node;

printf("gap %d, percentage %d,Numtrial
%d\n",gapValue,perCentage,numTrial);
}
}
}

Suppose the percentage should be 0.0. 1.0, 2.0 . however the value is
0.0 , -1610612736
The numTrial should be 0, 1,2,3,4,, however the value is 0,1069128089.

Why, is my declariation sth wrong, if I delete the "static", same thing
happens.

Thanks for any comments.

Feb 9 '06 #1
5 1568
yezi wrote:
HI:

The code I write is :

static int numTrial;
static float perCentage;
static int gapValue;
static int inValue;
for( gapValue = inValue; gapValue <= MAX_GAP; gapValue = (gapValue +
GAP_STEP)){

for (perCentage = 0.0; perCentage <= 1.0;perCentage = (perCentage
+0.1)){

for (numTrial = 0; numTrial < 5 ; numTrial ++){

Send packet sequence to the End Node;

printf("gap %d, percentage %d,Numtrial
%d\n",gapValue,perCentage,numTrial);
}
}
}
This code is not valid, compiling C.
Provide a minimal example.
Suppose the percentage should be 0.0. 1.0, 2.0 . however the value is
0.0 , -1610612736
The numTrial should be 0, 1,2,3,4,, however the value is 0,1069128089.
Read
http://c-faq.com/fp/index.html
If there are still questions afterwards, feel free to ask.

Why, is my declariation sth wrong, if I delete the "static", same thing
happens.


I would be puzzled if it did change the behaviour drastically.
Reread the parts about "static" in your textbook.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Feb 10 '06 #2
On 9 Feb 2006 15:33:49 -0800, in comp.lang.c , "yezi"
<ye*****@hotmail.com> wrote:
static float perCentage; printf("gap %d, percentage %d,Numtrial %d\n",gapValue,perCentage,numTrial);


perCentage is a float, you're trying to print it with %d.

Please read your C book to learn about the format specifiers for
printf.

Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 10 '06 #3
Mark McIntyre wrote:
On 9 Feb 2006 15:33:49 -0800, in comp.lang.c , "yezi"
<ye*****@hotmail.com> wrote:

static float perCentage;


printf("gap %d, percentage %d,Numtrial %d\n",gapValue,perCentage,numTrial);

perCentage is a float, you're trying to print it with %d.


....and "percentage" is one word (no need for camel casing).
August

--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
Feb 10 '06 #4
yezi wrote:
[...]
static int numTrial;
static float perCentage;
static int gapValue; [...] printf("gap %d, percentage %d,Numtrial %d\n",gapValue,perCentage,
numTrial);

[...]

You lied to printf. You told it to expect an int as the second value,
and then gave it perCentage, which is a float.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Feb 10 '06 #5
August Karlstrom wrote
(in article <il*******************@newsb.telia.net>):
Mark McIntyre wrote:
On 9 Feb 2006 15:33:49 -0800, in comp.lang.c , "yezi"
<ye*****@hotmail.com> wrote:

static float perCentage;


printf("gap %d, percentage %d,Numtrial %d\n",gapValue,perCentage,numTrial);

perCentage is a float, you're trying to print it with %d.


...and "percentage" is one word (no need for camel casing).


Hmmm. I had to go look up "Camel casing", having never heard it
described as that before. Informative wiki article. Now I know
why I haven't head it. It was made up only 11 years ago, or
"yesterday". :-)

I have heard it referred to as medial capitals though.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Feb 11 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: bryan | last post by:
I think I'm missing something fundamental here. I'm trying to set an unsigned long value via a u_long pointer, however it coredumps everytime I get to that instruction. Here is a sample program...
8
by: Ricardo Sta. Rita | last post by:
Hello people, We have been dealing with for a long time now. It's a bit weird for a newcomer like us so we decided to ask the geniuses here. C# doesn't seem to be assigning values, consider...
5
by: marcmc | last post by:
Is it in any way possible to have a sProc called and executed within SQLServer return its return value to an open .Net Vb application? As a programmer I beleive this can be done and if I wreck my...
16
by: Bill Nguyen | last post by:
I'm running into a very weird problem regarding subtraction. Subtraction behaves as if it's an addition in the below sub txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####0") ...
4
by: Clint Weisbrod | last post by:
All, I'm creating an STL map object like this: map<double, stringmyMap; I add a few items to the map using the operator. If I iterate over the map like:
2
by: kigoobe | last post by:
I am having a very weird issue here, a simple form submit not working. Trying for several hours now ... must be something stupid ... help appreciated. First, the html - <form id="formFinale"...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
13
by: Dave Rado | last post by:
Hi The W3C css validation service at http://jigsaw.w3.org/css-validator/ claims that: {font-family: "Book Antiqua", Palatino, "Times New Roman", "Times Roman" serif} is invalid on the...
0
by: hhoang.nl | last post by:
I have a very weird problem with the GridView control. Here is the code: <asp:GridView runat="server" ID="gv" AutoGenerateEditButton="true" AutoGenerateSelectButton="true" AllowPaging="true"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.