RSS Forums RSS

creating a infinate loop

Please support our C++ advertiser: Programming Forums
Reply
Posts: 15
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

  #1  
Aug 15th, 2008
so this is what I have done
#include<iostream>

#include<string>
void menu();

using namespace std;
char choice;

void digcom ();

void matrices ();

int main ()

{ menu();



return 0;

}
void menu()
{
cout<<"\tMENU" <<endl<<"MATHEMATICS(matrices select A)\n"<<"DIGITAL COMMS select B\n"<<"c TO EXIT"<<endl;

cin>>choice;

while(choice!='c')
{

switch(choice)

{

case ('A') : matrices();break;

case ('B'): digcom();break;

default:cout<<"re-enter\n";
cin>>choice;break;

}
}
}// end of menu

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



void matrices() // new function
{

int q1[4],q2[4],q3[4];
float da,dx,dy,dz,x,y,z,*ptr2;;
cout<<"\nTHE EQUATION MUST BE ENTERED USING CO-OEFICIENTS ONLY"<<endl
    <<"ENTER EQUATION 1"<<endl;
  for(int a=0;a<=3;a++)
    {
      cin>>q1[a];
    }

cout<<"\nEQUATION 1 COMPLETE, ENTER EQUATION 2"<<endl;

 for(int b=0;b<=3;b++)
   {
    cin>>q2[b];
   }

cout<<"\nEQUATION 2 COMPLETE, ENETR EQUATION3"<<endl;
 for(int c=0;c<=3;c++)
   {
    cin>>q3[c];
   }
int d,e,f,*pointer1;
// DET A
   pointer1=q1;
   d=*pointer1*((q2[1]*q3[2])-(q3[1]*q2[2]));
   pointer1++;
   e=*pointer1*((q2[0]*q3[2])-(q3[0]*q2[2]));
   pointer1++;
   f=*pointer1*((q2[0]*q3[1])-(q3[0]*q2[1]));
   pointer1++;
   da=d-e+f;

//DET X
   d=*pointer1*((q2[1]*q3[2])-(q3[1]*q2[2]));
   pointer1-=2;
   e=*pointer1*((q2[3]*q3[2])-(q3[3]*q2[2]));
   pointer1++;
   f=*pointer1*((q2[3]*q3[1])-(q3[3]*q2[1]));
   dx=d-e+f;

//DET Y
   pointer1=q1;
   d=*pointer1*((q2[3]*q3[2])-(q3[3]*q2[2]));
   pointer1+=3;
   e=*pointer1*((q2[0]*q3[2])-(q3[0]*q2[2]));
   pointer1--;
   f=*pointer1*((q2[0]*q3[3])-(q3[0]*q2[3]));
   dy=d-e+f;

//DET Z
   pointer1=q1;
   d=*pointer1*((q2[1]*q3[3])-(q3[1]*q2[3]));
   pointer1++;
   e=*pointer1*((q2[0]*q3[3])-(q3[0]*q2[3]));
   pointer1+=2;
   f=*pointer1*((q2[0]*q3[1])-(q3[0]*q2[1]));
   dz=d-e+f;


float t[3];
t[0]=dx/da;
t[1]=dy/da;
t[2]=dz/da;


cout<<"\n...........OPTIONS........."<<endl
    <<"1. CALCULATE THE VALUE OF X"<<endl
    <<"2. CALCULATE THE VALUE OF Y"<<endl
    <<"3. CALCULATE THE VALUE OF Z"<<endl
    <<"4. CALCULATE ALL THE VALUES"<<endl
    <<endl<<"ENTER YOUR CHOICE"<<endl;
cin>>d;

if(d==4)
 {
  ptr2=t;
  cout<<"THE VALUE OF X IS: "<<*ptr2<<endl;
  ptr2++;
  cout<<"THE VALUE OF Y IS: "<<*ptr2<<endl;
  ptr2++;
  cout<<"THE VALUE OF Z IS: "<<*ptr2<<endl;
 }

  else
   {
    cout<<"THE VALUE IS: "<<t[d-1]<<endl;
   }
menu();
}


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 1:43 pm. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Posts: 5,068
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 
Solved Threads: 355
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: creating a infinate loop

  #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 7:41 am.
*Voted best profile in the world*
Reply With Quote  
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: 205
mitrmkar mitrmkar is offline Offline
Posting Shark

Re: creating a infinate loop

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

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Views: 391 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:28 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC