|
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
|