Dear group,
I wrote a simple code trying to use the integer index of a "for" loop inside
the loop. The idea is to convert it to double type and lead it into a
function. However it appears I can't call the integer number directly inside
the loop, otherwise, the results are not sensible.
The code is as the following,
int main()
{
int i;
double min, max,modl,tt;
max=PI/2;
for (i=1;i<=90;i++)
{
9---> min=i/radian;
modl=background +Gaussian_quadr ature(max,min);
printf("%d \t %6.4f \n",i,modl);
tt=tt+1.;
}
system("pause") ;
return 0;
}
I tried min= (double)i/radian in line 9 as well. It does not give the right
result either. Eventually, I defined another variable tt, initialized it to
be 1 outside of the loop and increased it by one per loop. I want to know
why I could not use the index inside loop. Thanks!
Fan 8 1628
Fan Zhang <fa******@sas.u penn.edu> spoke thus: int main() { int i; double min, max,modl,tt; max=PI/2;
for (i=1;i<=90;i++) { 9---> min=i/radian; }
Presumably your real code defines the variable "radian"; why don't you
post it? Whatever radian is, perhaps you've neglected to assign
something meaningful to it.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
I forgot to mention that radian is a predefined value. It could not be the
problem, otherwise if I replace i with a double number the problem wont be
fixed.
Thanks for the input though.
"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:ck******** **@chessie.cirr .com... Fan Zhang <fa******@sas.u penn.edu> spoke thus:
int main() { int i; double min, max,modl,tt; max=PI/2;
for (i=1;i<=90;i++) { 9---> min=i/radian; }
Presumably your real code defines the variable "radian"; why don't you post it? Whatever radian is, perhaps you've neglected to assign something meaningful to it.
-- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
"Fan Zhang" wrote in message Dear group,
I wrote a simple code trying to use the integer index of a "for" loop
inside the loop. The idea is to convert it to double type and lead it into a function. However it appears I can't call the integer number directly
inside the loop, otherwise, the results are not sensible.
It's not a good idea to toy with the dummy you're using for the loop. I'd
declare a double and then assign it inside the loop with a caste of the
dummy.
The code is as the following,
int main() { int i; double min, max,modl,tt; max=PI/2;
for (i=1;i<=90;i++) { 9---> min=i/radian; modl=background +Gaussian_quadr ature(max,min); printf("%d \t %6.4f \n",i,modl); tt=tt+1.; } system("pause") ; return 0; }
Did this compile for you sans headers? My numerical analysis class was at
7:30 a.m., so I didn't pay much attention to things like background either
as I drooled on my desk. MPJ I tried min= (double)i/radian in line 9 as well. It does not give the
right result either. Eventually, I defined another variable tt, initialized it
to be 1 outside of the loop and increased it by one per loop. I want to know why I could not use the index inside loop. Thanks!
Fan
"Fan Zhang" <fa******@sas.u penn.edu> wrote in message
news:ck******** ***@netnews.upe nn.edu... I forgot to mention that radian is a predefined value.
From the perspective of the code you posted, no it's
not. Did you leave something out of your post? Without
seeing its definition (or at least your telling us exactly
what it is), we can't help much.
It could not be the problem,
Famous last words. :-)
otherwise if I replace i with a double number the problem wont be fixed.
There are also other entites referred to in your
code for which you don't show any defintion (e.g.
'background' and 'Gaussian_quadr ature')
You say your code gives incorrect results. So presumably
you have code which compiles (what you posted does not,
due to the missing definitions, as well as missing headers).
Post a compilable program.
And please don't top-post. Thanks.
-Mike
Fan Zhang wrote: Dear group,
I wrote a simple code trying to use the integer index of a "for" loop inside the loop. The idea is to convert it to double type and lead it into a function. However it appears I can't call the integer number directly inside the loop, otherwise, the results are not sensible.
The code is as the following,
int main() { int i; double min, max,modl,tt;
Prefer to define one variable per line. Makes modifications
easier.
max=PI/2;
Let us hope that PI is a double or a float.
This should be:
max = PI / 2.0;
The '.' indicates to the compiler to use a floating point
constant rather than an integral one. for (i=1;i<=90;i++)
Should this be from zero to less than 90?
for (i = 0; i < 90; ++i)
{ 9---> min=i/radian;
Well, you had better look up the type for "radian".
If it is an integer, you will have precision problems.
You are dividing an integer by either an integral or
floating point value (i.e. radian). You should have
your numbers either all floating point or all integral.
min = (double) i / /* (double) */ radian;
modl=background +Gaussian_quadr ature(max,min);
Validate the return type of Gaussian_quadra ture and
also of "background ". Again, to maintain numeric
"correctnes s", have all values the same type in a
mathematical expression.
printf("%d \t %6.4f \n",i,modl); tt=tt+1.;
Prefer to have digits after decimal points. This makes
reading easier and syntax errors fewer.
tt = tt + 1.0;
} system("pause") ; return 0; }
I tried min= (double)i/radian in line 9 as well. It does not give the right result either. Eventually, I defined another variable tt, initialized it to be 1 outside of the loop and increased it by one per loop. I want to know why I could not use the index inside loop. Thanks!
Fan
There are many problems here:
1. We have no idea how to differentiate expected results
from actual results. The above snippet program does
not compile.
2. Because you snippet is not complete, we cannot confirm
that your problems are not elsewhere (like maybe in
Gaussian_quadra ture).
3. Please describe the requirements and behavior of your
complete program. This will help others help you.
--
Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq: http://www.comeaucomputing.com/learn/faq/
Other sites: http://www.josuttis.com -- C++ STL Library book
"Fan Zhang" <fa******@sas.u penn.edu> writes: I forgot to mention that radian is a predefined value. It could not be the problem, otherwise if I replace i with a double number the problem wont be fixed.
We don't know that; if you don't post the actual code that you
compiled, we can't tell where the problem is.
Where is "radian" predefined? What does its declaration look like?
Reduce your program to a small example that exhibits the problem, one
that we can cut-and-paste, compile, and execute on our own systems.
If the workings of the Gaussian_quadra ture function are irrelevant,
just print the values of min and max. Tells us what output you're
getting and what output you expected.
Looking at your original (incomplete) program, I see a call to
Gaussian_quadra ture with arguments max and min, but I don't see an
initialization of min. We can only guess whether that's the problem.
Please don't make us guess.
Also, please don't top-post. In a followup, your response should
follow any quoted text. See any article in this newsgroup (including
this one) for an example.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Thanks for everybody's input. The problem was from the definition of radian.
I figured it out after reading the posts. Thanks a lot!
"Thomas Matthews" <Th************ *************** *@sbcglobal.net > wrote in
message news:dl******** **********@news svr33.news.prod igy.com... Fan Zhang wrote: Dear group,
I wrote a simple code trying to use the integer index of a "for" loop inside the loop. The idea is to convert it to double type and lead it into a function. However it appears I can't call the integer number directly inside the loop, otherwise, the results are not sensible.
The code is as the following,
int main() { int i; double min, max,modl,tt; Prefer to define one variable per line. Makes modifications easier.
max=PI/2; Let us hope that PI is a double or a float. This should be: max = PI / 2.0; The '.' indicates to the compiler to use a floating point constant rather than an integral one.
for (i=1;i<=90;i++)
Should this be from zero to less than 90? for (i = 0; i < 90; ++i)
{ 9---> min=i/radian; Well, you had better look up the type for "radian". If it is an integer, you will have precision problems. You are dividing an integer by either an integral or floating point value (i.e. radian). You should have your numbers either all floating point or all integral. min = (double) i / /* (double) */ radian;
modl=background +Gaussian_quadr ature(max,min); Validate the return type of Gaussian_quadra ture and also of "background ". Again, to maintain numeric "correctnes s", have all values the same type in a mathematical expression.
printf("%d \t %6.4f \n",i,modl); tt=tt+1.; Prefer to have digits after decimal points. This makes reading easier and syntax errors fewer. tt = tt + 1.0;
} system("pause") ; return 0; }
I tried min= (double)i/radian in line 9 as well. It does not give the right result either. Eventually, I defined another variable tt, initialized it to be 1 outside of the loop and increased it by one per loop. I want to know why I could not use the index inside loop. Thanks!
Fan
There are many problems here: 1. We have no idea how to differentiate expected results from actual results. The above snippet program does not compile.
2. Because you snippet is not complete, we cannot confirm that your problems are not elsewhere (like maybe in Gaussian_quadra ture).
3. Please describe the requirements and behavior of your complete program. This will help others help you.
-- Thomas Matthews
C++ newsgroup welcome message: http://www.slack.net/~shiva/welcome.txt C++ Faq: http://www.parashift.com/c++-faq-lite C Faq: http://www.eskimo.com/~scs/c-faq/top.html alt.comp.lang.l earn.c-c++ faq: http://www.comeaucomputing.com/learn/faq/ Other sites: http://www.josuttis.com -- C++ STL Library book
"Fan Zhang" <fa******@sas.u penn.edu> writes: Thanks for everybody's input. The problem was from the definition of radian. I figured it out after reading the posts. Thanks a lot!
Just out of curiosity, can you tell us (briefly) what the problem was?
And again, please don't top-post.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: johnny |
last post by:
Can anyone tell me what is wrong with the following code fragment?
char a = x;
char b = y;
int result = strtol(&a, NULL, 10) + strtol(&b, NULL, 10);
I got the same result using result=atoi(&a)+atoi(&b);
cout << a << '\t' << b << endl; shows the values of a and b to be correct.
|
by: jprunier |
last post by:
Hi
I isolated this code which gives me odd results and I am not sure to
understand why. Basically I declared "positions" as a map that I am using to
store pairs of integers. The key used for the map is an integer as well.
When I access the values of a pair by using a "normal" integer as an index
to access the elements positions contains, it works fine. If I use an
integer that I created using the random() function, then the first value...
|
by: John |
last post by:
Hello everyone,
I'm currently writing a program to keep track of schedule changes at a
school. The goal is to have someone using the program to declare changes,
then the program writes a html file, which is uploaded to a webserver. Then
students and teachers can view it online, but there are also a couple of
computers with 19" monitors standing around the school to display the
webpage (IE kiosk mode).
The program has a form containing...
|
by: John Baker |
last post by:
When declaring an integer, you can specify the size by using int16,
int32, or int64, with plain integer being int32.
Is integer the accepted default in the programming community?
If so, is there a way to remove the ones with size predefined from the
autolisting of types when I am declaring something?
--
To Email Me, ROT13 My Shown Email Address
|
by: coinjo |
last post by:
Is there any function to determine the length of an integer string?
| |
by: Barry |
last post by:
Hello,
In VS2003, I tried using an enum and setting it into a field in a
datarow. It seems as if the datatype of the field in the row
determined what went into the field. If the datatype was string, then
the name of the enum item went into the field, but if the datatype was
integer, then the integer value of the enum was stored.
Is this expected behaviour? I couldn't find anything while searching
for answers.
|
by: chutsu |
last post by:
I'm trying to compare between pointer and integer in an "IF" statement
how do I make this work?
if(patient.id != NULL){
}
Thanks
Chris
|
by: no1zson |
last post by:
I do not even know how to correctly ask this question.
I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number.
Over the last week I have played with Add buttons, Del buttons, Modify and everything else and it brought to light a problem I want to address today.
I have always just used 1 for the first item, 2 for the second and so on ...
well after I am done will all...
|
by: =?Utf-8?B?dG9iaXdhbl9rZW5vYmk=?= |
last post by:
The following code is in a custom deserializer:
object value = (int) 1;
string nameToParse = Enum.GetName(field.FieldType, value);
value = Enum.Parse(field.FieldType, nameToParse);
Currently we follow the path below:
intValue --enum name --enum value
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |