View Single Post
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