View Single Post
Join Date: Aug 2005
Posts: 5,264
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: 376
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