creating a infinate loop

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 16
Reputation: STUDENT#101 is an unknown quantity at this point 
Solved Threads: 1
STUDENT#101 STUDENT#101 is offline Offline
Newbie Poster

creating a infinate loop

 
0
  #1
Aug 15th, 2008
so this is what I have done
  1. #include<iostream>
  2.  
  3. #include<string>
  4. void menu();
  5.  
  6. using namespace std;
  7. char choice;
  8.  
  9. void digcom ();
  10.  
  11. void matrices ();
  12.  
  13. int main ()
  14.  
  15. { menu();
  16.  
  17.  
  18.  
  19. return 0;
  20.  
  21. }
  22. void menu()
  23. {
  24. cout<<"\tMENU" <<endl<<"MATHEMATICS(matrices select A)\n"<<"DIGITAL COMMS select B\n"<<"c TO EXIT"<<endl;
  25.  
  26. cin>>choice;
  27.  
  28. while(choice!='c')
  29. {
  30.  
  31. switch(choice)
  32.  
  33. {
  34.  
  35. case ('A') : matrices();break;
  36.  
  37. case ('B'): digcom();break;
  38.  
  39. default:cout<<"re-enter\n";
  40. cin>>choice;break;
  41.  
  42. }
  43. }
  44. }// end of menu
  45.  
  46. void digcom()
  47.  
  48. {
  49.  
  50. string ans;
  51.  
  52. int *score;
  53.  
  54. score=new int; // dynamic memory allocation
  55.  
  56. if(score==NULL)
  57.  
  58. {
  59.  
  60. cerr<<"insufitient space could not allocate memory"<<endl;
  61.  
  62. exit(1);
  63.  
  64. }
  65.  
  66. string questions[10]={"State the basic form of representation of a image","What does LAN stand for","What type of data transmission allows data to only flow in one direction","in a wireless network data is transmitted at the speed of __","which is___","determine the propagation delay associated with a connectionless communication channel through a private telephone network","What does modem stand for","what does IP stand for","what format is used to store data"};
  67.  
  68. string answers[10]={"pixels","Local Area Network","simplex","light,5*10^-8","5*10^-6","modulator-demodulator","Internet Protocol","digital format"};
  69.  
  70. string store[10];
  71.  
  72. cout<<"MAKE SURE THAT UR ANSWERS ARE IN SMALL LETTER UNLESS STATING THE ABBREVIATION"<<endl;
  73.  
  74. *score=0;
  75.  
  76. for(int n=0;n<9;n++)
  77.  
  78. {
  79.  
  80. cout<<questions[n]<<endl;
  81.  
  82. getline(cin,ans);
  83.  
  84. int f=ans.length();
  85.  
  86. store[n]=ans.substr(0,f); // string function
  87.  
  88. }
  89.  
  90. for(int i=0;i<10;i++)
  91.  
  92. {
  93.  
  94. if(answers[i]==store[i])
  95.  
  96. {
  97.  
  98. *score++; // pointer is incremented possible use before definition
  99.  
  100. }
  101.  
  102. }
  103.  
  104. cout<<"you got "<<*score<<"/10"<<endl;
  105.  
  106. delete score;
  107.  
  108.  
  109. menu();
  110.  
  111. } // end of this function
  112.  
  113.  
  114.  
  115. void matrices() // new function
  116. {
  117.  
  118. int q1[4],q2[4],q3[4];
  119. float da,dx,dy,dz,x,y,z,*ptr2;;
  120. cout<<"\nTHE EQUATION MUST BE ENTERED USING CO-OEFICIENTS ONLY"<<endl
  121. <<"ENTER EQUATION 1"<<endl;
  122. for(int a=0;a<=3;a++)
  123. {
  124. cin>>q1[a];
  125. }
  126.  
  127. cout<<"\nEQUATION 1 COMPLETE, ENTER EQUATION 2"<<endl;
  128.  
  129. for(int b=0;b<=3;b++)
  130. {
  131. cin>>q2[b];
  132. }
  133.  
  134. cout<<"\nEQUATION 2 COMPLETE, ENETR EQUATION3"<<endl;
  135. for(int c=0;c<=3;c++)
  136. {
  137. cin>>q3[c];
  138. }
  139. int d,e,f,*pointer1;
  140. // DET A
  141. pointer1=q1;
  142. d=*pointer1*((q2[1]*q3[2])-(q3[1]*q2[2]));
  143. pointer1++;
  144. e=*pointer1*((q2[0]*q3[2])-(q3[0]*q2[2]));
  145. pointer1++;
  146. f=*pointer1*((q2[0]*q3[1])-(q3[0]*q2[1]));
  147. pointer1++;
  148. da=d-e+f;
  149.  
  150. //DET X
  151. d=*pointer1*((q2[1]*q3[2])-(q3[1]*q2[2]));
  152. pointer1-=2;
  153. e=*pointer1*((q2[3]*q3[2])-(q3[3]*q2[2]));
  154. pointer1++;
  155. f=*pointer1*((q2[3]*q3[1])-(q3[3]*q2[1]));
  156. dx=d-e+f;
  157.  
  158. //DET Y
  159. pointer1=q1;
  160. d=*pointer1*((q2[3]*q3[2])-(q3[3]*q2[2]));
  161. pointer1+=3;
  162. e=*pointer1*((q2[0]*q3[2])-(q3[0]*q2[2]));
  163. pointer1--;
  164. f=*pointer1*((q2[0]*q3[3])-(q3[0]*q2[3]));
  165. dy=d-e+f;
  166.  
  167. //DET Z
  168. pointer1=q1;
  169. d=*pointer1*((q2[1]*q3[3])-(q3[1]*q2[3]));
  170. pointer1++;
  171. e=*pointer1*((q2[0]*q3[3])-(q3[0]*q2[3]));
  172. pointer1+=2;
  173. f=*pointer1*((q2[0]*q3[1])-(q3[0]*q2[1]));
  174. dz=d-e+f;
  175.  
  176.  
  177. float t[3];
  178. t[0]=dx/da;
  179. t[1]=dy/da;
  180. t[2]=dz/da;
  181.  
  182.  
  183. cout<<"\n...........OPTIONS........."<<endl
  184. <<"1. CALCULATE THE VALUE OF X"<<endl
  185. <<"2. CALCULATE THE VALUE OF Y"<<endl
  186. <<"3. CALCULATE THE VALUE OF Z"<<endl
  187. <<"4. CALCULATE ALL THE VALUES"<<endl
  188. <<endl<<"ENTER YOUR CHOICE"<<endl;
  189. cin>>d;
  190.  
  191. if(d==4)
  192. {
  193. ptr2=t;
  194. cout<<"THE VALUE OF X IS: "<<*ptr2<<endl;
  195. ptr2++;
  196. cout<<"THE VALUE OF Y IS: "<<*ptr2<<endl;
  197. ptr2++;
  198. cout<<"THE VALUE OF Z IS: "<<*ptr2<<endl;
  199. }
  200.  
  201. else
  202. {
  203. cout<<"THE VALUE IS: "<<t[d-1]<<endl;
  204. }
  205. menu();
  206. }


theproblem is with the digcom after it has run it tells me of a error abou the pointer
Last edited by Tekmaven; Aug 15th, 2008 at 2:43 pm. Reason: Code tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: creating a infinate loop

 
0
  #2
Aug 15th, 2008
What are you inputting for digcom?

Show us an exact example

void digcom()
{
  string ans;
  int *score;
  score = new int; // dynamic memory allocation

  if ( score == NULL )
  {
    cerr << "insufitient space could not allocate memory" << endl;
    exit ( 1 );
  }

  string questions[10] = {"State the basic form of representation of a image", "What does LAN stand for", "What type of data transmission allows data to only flow in one direction", "in a wireless network data is transmitted at the speed of __", "which is___", "determine the propagation delay associated with a connectionless communication channel through a private telephone network", "What does modem stand for", "what does IP stand for", "what format is used to store data"};
  string answers[10] = {"pixels", "Local Area Network", "simplex", "light,5*10^-8", "5*10^-6", "modulator-demodulator", "Internet Protocol", "digital format"};

  string store[10];

  cout << "MAKE SURE THAT UR ANSWERS ARE IN SMALL LETTER UNLESS STATING THE ABBREVIATION" << endl;

  *score = 0;

  for ( int n = 0; n < 9; n++ )
  {
    cout << questions[n] << endl;
    getline ( cin, ans );
    int f = ans.length();
    store[n] = ans.substr ( 0, f ); // string function
  }

  for ( int i = 0; i < 10; i++ )
  {
    if ( answers[i] == store[i] )
    {
      *score++; // pointer is incremented possible use before definition
    }
  }

  cout << "you got " << *score << "/10" << endl;

  delete score;
  menu();

} // end of this function

Plus you don't need a pointer to simply increment a score count. Hell you don't even need an array. The part in red doesn't make sense either.
Last edited by iamthwee; Aug 15th, 2008 at 8:41 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 978
Reputation: mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice mitrmkar is just really nice 
Solved Threads: 208
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: creating a infinate loop

 
0
  #3
Aug 15th, 2008
Please take the time you need to get familiar with code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC