CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Aug 2005
    Posts
    22

    What am i missing?

    Code:
    void displayMenu()
    {
       do
       {
    		clrscr();
       	cout << "                            " << endl;
    		cout << "  ---------------------------          " << endl;
      		cout << "  Welcome to the Video System                 " << endl;
    		cout << "  ---------------------------          " << endl;
       	cout << "                            " << endl;
    		cout << "  1.  Add New Video                       " << endl;
    		cout << "  2.  Borrow Video                         " << endl;
    		cout << "  3.  Modify Video Record                    " << endl;
    		cout << "  4.  Delete Video                         " << endl;
    		cout << "  5.  Report of Available videos 		          " << endl;
    		cout << "  6.  Exit								       ";
    		cout << "                            " << endl;
       	cout << "  Please select an option 1-6: ";
    		cin >> option;
    
    		switch(option)
    		{
    		case 1:
    			doAdd();
    			break;
    		case 2:
    			doBorrow();
    			break;
    		case 3:
    			doModify();
    			break;
    		case 4:
    			doDelete();
    			break;
    		case 5:
    			doReport();
    			break;
    		case 6:
    			doExit();
    			break;
      	   default:
         		cout << "Error: Invalid Option";
    			break;
      	   }
    	while(option != 1 && option != 2 && option != 3 && option != 4 && option != 5 && option != 6);
    )
    Error:test.cpp(102,2):Expression syntax
    Error:test.cpp(103,1):Statement missing ;
    Error:test.cpp(103,1):Compound statement missing }
    Error:test.cpp(103,1)o statement must have while
    Error:test.cpp(103,1):Compound statement missing }

  2. #2
    Join Date
    Sep 2004
    Location
    A Planet Called Earth... :-)
    Posts
    835

    Re: What am i missing?

    Looks like u are missing a few braces.

    Quote Originally Posted by bradleyc
    Code:
    void displayMenu()
    {
     	do
     	{
    		clrscr();
    		cout << " " << endl;
    			cout << " --------------------------- " << endl;
    			cout << " Welcome to the Video System " << endl;
    			cout << " --------------------------- " << endl;
    		cout << " " << endl;
    			cout << " 1. Add New Video " << endl;
    			cout << " 2. Borrow Video " << endl;
    			cout << " 3. Modify Video Record " << endl;
    			cout << " 4. Delete Video " << endl;
    			cout << " 5. Report of Available videos		 " << endl;
    			cout << " 6. Exit								 ";
    			cout << " " << endl;
    		cout << " Please select an option 1-6: ";
    			cin >> option;
    
    			switch(option)
    			{
    			case 1:
    				doAdd();
    				break;
    			case 2:
    				doBorrow();
    				break;
    			case 3:
    				doModify();
    				break;
    			case 4:
    				doDelete();
    				break;
    			case 5:
    				doReport();
    				break;
    			case 6:
    				doExit();
    				break;
    		 default:
    			cout << "Error: Invalid Option";
    				break;
    		 }
    	}
     	while(option != 1 && option != 2 && option != 3 && option != 4 && option != 5 && option != 6);
    }//NOT )
    Error:test.cpp(102,2):Expression syntax
    Error:test.cpp(103,1):Statement missing ;
    Error:test.cpp(103,1):Compound statement missing }
    Error:test.cpp(103,1)o statement must have while
    Error:test.cpp(103,1):Compound statement missing }
    C++ program ran... C++ program crashed... C++ programmer quit !!

    Regards

    Shaq

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: What am i missing?

    Some inputs from my side:
    1. clrscr() is not a part of standard C++.
    2. The variable 'option' is not defined anywhere in the function.
    3. The missing and mismatched braces as pointed by Vedam Shashank
    4. This code:
    Code:
    while(option != 1 && option != 2 && option != 3 && option != 4 && option != 5 && option != 6);
    could be easily replaced with a simpler version:
    Code:
    while(option<1 && option>6);
    I assume the definitions of the various functions being used are there. HTH. Regards.

  4. #4
    Join Date
    Aug 2005
    Posts
    22

    Re: What am i missing?

    Than whats wrong with ... sorry, i just cant see it ...

    Code:
    void doDelete()
    {
    	clrscr();
       char inputv, input;
       cout << "                      " << endl;
       cout << "  --- DELETE VIDEO MENU ----                 " << endl;
       cout << "  Would you like to delete a video (y/n)?: ";
       cin >> inputv;
       if (inputv == 'y' || inputv == 'Y')
       	(
           	int item, location;
          	clrscr();
          	cout << "                      " << endl;
          	cout << "  What is the video's name ? ";
           	cin >> item;
           	location = searchName(videoLib, numElements, item);
           	if (location == -1)
           		(
             	clrscr();
             	cout << "                      " << endl;
             	cout << "  Invaild Input" <<endl;
             	cout << "  Press any key to exit ....";
    				input = getch();
            		}
           	else
             {
           		{
           		for(int i = location; i < numElements - 1; i++)
           		}
             	videoLib[i] = videoLib[i++];
          	}
       	}
    }

  5. #5
    Join Date
    Jun 2005
    Posts
    1,255

    Re: What am i missing?

    There is a mismatch between the opening parenthesis "(" and the opening brace "{". It occurs twice in your code. Do you see?

  6. #6
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: What am i missing?

    Quote Originally Posted by bradleyc
    Than whats wrong with ... sorry, i just cant see it ...

    Code:
    void doDelete()
    {
    	clrscr();
       char inputv, input;
       cout << "                      " << endl;
       cout << "  --- DELETE VIDEO MENU ----                 " << endl;
       cout << "  Would you like to delete a video (y/n)?: ";
       cin >> inputv;
       if (inputv == 'y' || inputv == 'Y')
       	(
           	int item, location;
          	clrscr();
          	cout << "                      " << endl;
          	cout << "  What is the video's name ? ";
           	cin >> item;
           	location = searchName(videoLib, numElements, item);
           	if (location == -1)
           		(
             	clrscr();
             	cout << "                      " << endl;
             	cout << "  Invaild Input" <<endl;
             	cout << "  Press any key to exit ....";
    				input = getch();
            		}
           	else
             {
           		{// what's the nee for this braces
           		for(int i = location; i < numElements - 1; i++)
           		}
             	videoLib[i] = videoLib[i++];
          	}
       	}
    }
    Just check out Your code Once again clearfully

    syntax and logic That's all you have to do,don't know for what u r trying any way what is this

    just check for following step

    1) check for your all opening and closed {} & () braces


    2) check for your for loop

    3) for loop execute only next statement after the loop .if multipel statement is there put all in Braces. your for loop i don't know what r doing

    4) Multiple time increment of i
    Code:
    //what's the need of this.
           else
             {
           	{// what's the nee for this braces
           	for(int i = location; i < numElements - 1; i++)
           	}
            	videoLib[i] = videoLib[i++];
          }
    //it should be like
           else
             {
                  	for(int i = location; i < numElements - 1; i++)
           	videoLib[i] = videoLib[i++];//no need to increment i when u r already doing in loop & what's the meaning of this statement.
          }
    Last edited by humptydumpty; September 9th, 2005 at 02:24 AM.

  7. #7
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: What am i missing?

    Quote Originally Posted by humptydumpty
    4) Multiple time increment of i
    videoLib[i] = videoLib[i++];
    videoLib[i] = videoLib[i++];//no need to increment i when u r
    Ok..What he wants to do seems logical. He needs to assign the nth videoLib member to (n-1)th one. But the construct is wrong. He might have had thought of achieving this:
    Code:
    for(.....;...;++i)
    {
        //....
        videoLib[i] = videoLib[i+1];
        //....
    }
    Humptydumpty - you traced it but you, i think, forgot to make the change . Regards.

    EDIT: The logic for deleting the video is wrong. You are just over-writing the data by shifting one location back and hence you are left with two copies (or more on subsequent calls to delete) of the same data at the end of the array or whatever you are using. This will ultimately screw up whole of the container (array) that you are using and what you will end up with would be a complete mess (upon subsequent additions, removals). Why don't you use std::list for maintaining a collection of videos in the library. It is best suited for you. (You could also use std::vector but removing this way in that also needs shifting all the rest of the members occuring later, one place ahead, although taken care of automatically - you dont need to worry about the shifting - just call erase() member function)
    Last edited by exterminator; September 9th, 2005 at 04:32 AM. Reason: is = will

  8. #8
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Thumbs up Re: What am i missing?

    Quote Originally Posted by exterminator
    Ok..What he wants to do seems logical. He needs to assign the nth videoLib member to (n-1)th one. But the construct is wrong. He might have had thought of achieving this:
    Code:
    for(.....;...;++i)
    {
        //....
        videoLib[i] = videoLib[i+1];
        //....
    }
    Humptydumpty - you traced it but you, i think, forgot to make the change . Regards.
    no exterminator i didn't forget anything just pointed out what he is doing that's all. i told him all the possibility and ask him to do all of his work and then move ahead.

    and one thing more
    Code:
    Moved
    Second thing in for loop either you write ++i or i++ both will work same.
    anyway thanx.
    Last edited by humptydumpty; September 9th, 2005 at 04:38 AM.

  9. #9
    Join Date
    Aug 2005
    Posts
    22

    Sorry, still missing something...

    Definately need my eyes checked...

    Error:asstester.cpp(300,1)eclaration missing ;
    Error:asstester.cpp(300,1):Compound statement missing }

    Code:
    void doModify()
    {
    	clrscr();
       char inputv, input1, input2;
       cout << "                      " << endl;
       cout << "  --- MODIFY VIDEO MENU ----                 " << endl;
       cout << "  Would you like to modify a video (y/n)?: ";
       cin >> inputv;
       if (inputv == 'y' || inputv == 'Y')
       	{
           	clrscr();
           	int item1, location1, location2;
           	char item2[20];
           	cout << "                      " << endl;
           	cout << "  -- Current Record --    " << endl;
           	cout << "  What is the Video Number?: ";
           	cin >> item1;
           	location1 = searchNum(videoLib, numElements, item1);
           	if (location1 == -1)
           		{
             	clrscr();
             	cout << "                      " << endl;
             	cout << "  Invaild Input" <<endl;
             	cout << "  Press any key to exit ....";
    				input1 = getch();
            		 }
           	else
           	{
           	cout << "  What is the Video Name?: ";
          	cin >> item2;
          	location2 = searchName(videoLib, numElements, item2);
           	if (location2 == -1)
           		{
             	clrscr();
             	cout << "                      " << endl;
             	cout << "  Invaild Input" <<endl;
             	cout << "  Press any key to exit ....";
    				input2 = getch();
             	}
            	else
           	{
           	cout << "                      " << endl;
           	cout << "  -- New Record --    " << endl;
           	cout << "  What is the Video Number?: ";
           	cin >> videoLib[location1].videoNum;
           	cout << "  What is the Video Name?: ";
           	cin.getline(videoLib[location2].videoName, 30);
    			}
    		}
    }
    Last edited by bradleyc; September 9th, 2005 at 04:05 AM.

  10. #10
    Join Date
    Oct 2002
    Location
    Germany
    Posts
    6,205

    Re: What am i missing?

    [ merged ]

    bradleyc - Please donot create a new thread to continue an existing discussion. When you reply to an existing thread - those that helped you receive notifications that you need help again.

    This is in your interest.

    Thank you for your understanding.

    Best Regards,
    Siddhartha

  11. #11
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

    Thumbs up Re: What am i missing?

    Quote Originally Posted by humptydumpty
    videoLib[i] = videoLib[i+1];
    &
    videoLib[i] = videoLib[i++];
    //No difference both are same only
    No Humpty - they are not the same!!! Try this small code out:
    Code:
    #include <iostream>
    int main(){
    	int a[6] = {0,1,2,3,4,5};
    	for (int i=0;i<5;++i){
    		std::cout << a[i++] << "\t";
    	}
    	return 0;
    }
    Output:
    0 2 4
    Replacing a[i++] with a[i+1] doesnot modify i and hence the result would be
    1 2 3 4 5
    Regards.
    Last edited by exterminator; September 9th, 2005 at 04:23 AM.

  12. #12
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Lightbulb Re: What am i missing?

    Yes u r right.
    With for loop i was misplaced

    anyway thanx

  13. #13
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Sorry, still missing something...

    Quote Originally Posted by bradleyc
    Definately need my eyes checked...
    1) Get an editor that does brace matching. The Visual C++ editor, plus many third-party editors for Windows and Linux/UNIX exist that have this capability.

    2) Organize your code so that it is easily detected that there are missing braces.
    Code:
    void doModify()
    {
       clrscr();
       char inputv, input1, input2;
       cout << "                      " << endl;
       cout << "  --- MODIFY VIDEO MENU ----                 " << endl;
       cout << "  Would you like to modify a video (y/n)?: ";
       cin >> inputv;
       if (inputv == 'y' || inputv == 'Y')
       {
            clrscr();
            int item1, location1, location2;
            char item2[20];
            cout << "                      " << endl;
            cout << "  -- Current Record --    " << endl;
            cout << "  What is the Video Number?: ";
            cin >> item1;
            location1 = searchNum(videoLib, numElements, item1);
            if (location1 == -1)
            {
                clrscr();
                cout << "                      " << endl;
                cout << "  Invaild Input" <<endl;
                cout << "  Press any key to exit ....";
                input1 = getch();
            }
            else
            {
                cout << "  What is the Video Name?: ";
                cin >> item2;
                location2 = searchName(videoLib, numElements, item2);
               if (location2 == -1)
               {
                    clrscr();
                    cout << "                      " << endl;
                    cout << "  Invaild Input" <<endl;
                    cout << "  Press any key to exit ....";
                                    input2 = getch();
               }
               else
               {
                    cout << "                      " << endl;
                    cout << "  -- New Record --    " << endl;
                    cout << "  What is the Video Number?: ";
                    cin >> videoLib[location1].videoNum;
                    cout << "  What is the Video Name?: ";
                    cin.getline(videoLib[location2].videoName, 30);
               }
            }
        }
    }     // <-- This is missing
    You are missing the last ending brace.

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Aug 2005
    Posts
    22

    Re: What am i missing?

    1) Get an editor that does brace matching. The Visual C++ editor, plus many third-party editors for Windows and Linux/UNIX exist that have this capability.



    What other editors for Windows have this capability?

  15. #15
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: What am i missing?

    Quote Originally Posted by bradleyc
    What other editors for Windows have this capability?
    I know a good freeware text editor, which is very fast and small, and has parenthesis checking.
    http://www.crimsoneditor.com/

    You may also use google to search for other editors, if you don't like this one.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured