Hello,
I have written the below code, which should rotate within the first "for" loop 50 times but dont know for what reason its iterating only 49 times..? Can anyone pls find out what the mistake is and reply with correction. U can also run this on ur compiler and check!
//<code> - #include <iostream.h>
-
int main()
-
{
-
//clrscr();
-
float earlylatespc=0.5,remcodephase=0,tcode;
-
int blksize=50,i_ecode=0,count1=0,tcode2,cacode[15]={1,2,1,9,4,5,4,5,7,7,8,7,5,4,7};
-
int earlycode[50];
-
float codephasestep,check;
-
float ptcode[1000];
-
int promptcode[50],i_pcode=0,i_tcode=0;
-
-
codephasestep=(float)1023/(float)38192;
-
check=((blksize-1)*codephasestep+remcodephase);
-
cout<<"check is"<<check<<endl;
-
cout<<endl;
-
for(tcode=remcodephase;tcode<=check;)
-
{
-
ptcode[i_tcode]=tcode;
-
tcode2=ceil(tcode)+1;
-
promptcode[i_pcode]=cacode[tcode2]; //check here later coz may be u should make it cacode[tcode2-1];
-
i_pcode+=1;
-
count1+=1; //to check no of iterations
-
i_tcode+=1;
-
tcode=tcode+codephasestep;
-
cout<<"tcodes are"<<tcode<<endl;
-
}
-
cout<<endl;
-
cout<<"final tcode"<<tcode<<endl;
-
cout<<"final count"<<count1<<endl;
-
cout<<endl;
-
for(i_pcode=0;i_pcode<count1;i_pcode++)
-
{
-
cout<<promptcode[i_pcode]<<endl;
-
-
}
-
cout<<endl;
-
for(i_tcode=0;i_tcode<count1;i_tcode++)
-
{
-
cout<<ptcode[i_tcode]<<endl;
-
-
}
-
cout<<"count"<<count1<<endl;
-
cout<<"the 50th term is"<<ptcode[blksize]<<endl;
-
//remCodePhase = (tcode(blksize) + codePhaseStep) - 1023.0;
-
-
-
remcodephase = (ptcode[blksize] + codephasestep) ;//- 1023.0; // taken as ptcode[] instead of tcode[]
-
//He wants the last term
-
cout<<"remcodephase is"<<remcodephase<<endl;
-
-
-
getchar();
-
return 0;
-
}
If everything works fine, the output of remcodephase should be "1.3392857"
Thanks,
prads
1 1438
Have you used any breakpoints to determine what the values of some of your variables are to help you debug this? I didn't compile it, but just from taking a glance at it, and keep in mind that I haven't been using C++ for very long, it would appear as though perhaps your variables either haven't been initialized to the value that is needed to obtain the 50th position.
If you initialized to zero, remember that the 50th position will actually be the 49th memory location. If you initialize to 1 then 50 will be the 50th position. I could be way off base, but I'm definitely not trying to be condescending if you knew that already.
If you walk through your program using the breakpoints, you may notice that one of your values should be something else at a given location and that is what is throwing off the calculation.
Hope this helps.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mountain Bikn' Guy |
last post by:
Take some standard code such as shown below. It simply loops to add up a
series of terms and it produces the correct result.
// sum numbers with a loop
public int DoSumLooping(int iterations)
{...
|
by: Mountain Bikn' Guy |
last post by:
Take some standard code such as shown below. It simply loops to add up a
series of terms and it produces the correct result.
// sum numbers with a loop
public int DoSumLooping(int iterations)
{...
|
by: Microsoft |
last post by:
I have the following loop the length contains somewhere around 1000+ items:
For elemIndex = 0 To len - 1
elem = CType(doc.all.item(elemIndex), mshtml.IHTMLElement)
If elem.tagName = "A" Then
If...
|
by: ADezii |
last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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,...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |