Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-19-2003, 12:33 PM   #1 (permalink)
M3GAPL3X
Code Monkey
 
M3GAPL3X's Avatar
 
Join Date: Mar 2003
Location: California
Posts: 57
M3GAPL3X is on a distinguished road
Send a message via AIM to M3GAPL3X
Question do-while loop

Hi all,

I was just doing some basic looping in C++ and I can't seem to compile this program. It keeps giving me a:
"syntax error : '}'

I have taking } out and still doesn't seem to compile. If anyone could help, it would be greatly appreciated! Thanks in advance!

Here is the code. I am using the Visual C++ compiler.
Code:
/*
OUTPUT (MENU) à INPUT à SHOWINFO. à LOOP PROGRAM à END IF USER PRESSES >=6
*/

// Define the header file used in this program. 
#include <iostream.h>

int main()
{
	// Declare the selection variable
	int selectop;

	// Show the menu
	cout << "\t\t\t\tProgram About ME" << endl;
	cout << "\t\t\t\t----------------" << endl;
	cout << "\nClick appropriate number to view information" << endl;
	cout << "\n\n1. My Full Name " << endl;
	cout << "2. My Brother's and Sister's Name " << endl;
	cout << "3. My City and Country of Birth " << endl;
	cout << "4. My Favorite Book Title " << endl;
	cout << "5. My Favorite Movie " << endl;
	cout << "6. Exit the program " << endl;

	selectop = 1;

	do
	{
		switch(selectop)
		{
		case 1:
			cout << "My name is Menish Sharma " << endl;
			break;
	
		case 2:
			cout << "Unfortunately, I don't have a brother or sister. " << endl;
			break;

		case 3:
			cout << "I was born in Sacramento, California which is in the U.S. " << endl;
			break;

		case 4:
			cout << "My favorite book is Great Expectations. " << endl;
			break;
			
		case 5:
			cout << "My favorite movie is the Shawshank Redemption. " << endl;
			break;

		case 6:
			cout << "Exiting my program. " << endl;
break;

		default:
			cout << "The number " << selectop << " is not valid in this program. Please try again: ";
			break;

			return 0;
		}
		while (selectop <=6);
	}
}
__________________
--------------------------
M3GAPL3X@linuxmail.org
M3GAPL3X is offline   Reply With Quote
Old 06-19-2003, 12:57 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
your "while" should not be inside your "do" block.

Code:
do
{
  // something
} while(a == 1);
joe_bruin is offline   Reply With Quote
Old 06-19-2003, 01:04 PM   #3 (permalink)
M3GAPL3X
Code Monkey
 
M3GAPL3X's Avatar
 
Join Date: Mar 2003
Location: California
Posts: 57
M3GAPL3X is on a distinguished road
Send a message via AIM to M3GAPL3X
Thanks a lot joe_bruin!
Now I have to figure out how to make this program not loop forever!!

Thanks again.
__________________
--------------------------
M3GAPL3X@linuxmail.org
M3GAPL3X is offline   Reply With Quote
Old 06-21-2003, 08:52 AM   #4 (permalink)
ender
Code Monkey
 
ender's Avatar
 
Join Date: Mar 2003
Location: Evansville, IN
Posts: 75
ender is on a distinguished road
Send a message via AIM to ender Send a message via Yahoo to ender
Your problem lies in the fact that your test will only exit if you hit 7 or higher. This is due to the fact that <= says 'while it is less than or equal to 6, it is true." However, as your 'exit' happens ON six, you have to have 6 be an exit condition, so your loop should be something like:
Code:
do {
     // Some code
} while (someVar < 6);
Sorry if this sounds belittling, I didn't mean it to. Hope this helps.

Ted
__________________
while(1) fork();
ender is offline   Reply With Quote
Old 06-26-2003, 09:57 PM   #5 (permalink)
M3GAPL3X
Code Monkey
 
M3GAPL3X's Avatar
 
Join Date: Mar 2003
Location: California
Posts: 57
M3GAPL3X is on a distinguished road
Send a message via AIM to M3GAPL3X
Thanks ender, I'll be sure to get that down next time!
__________________
--------------------------
M3GAPL3X@linuxmail.org
M3GAPL3X is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
While loop not working alemily PHP 2 06-25-2004 12:07 PM
Breaking out of external loop agh Standard C, C++ 7 04-30-2003 08:03 PM
Loop in scripts causing Crashs mixingsoup PHP 2 12-01-2002 08:37 PM
the endless loop loop loop loop loop loop ... abc123 All Other Coding Languages 2 08-14-2002 03:43 PM


All times are GMT -8. The time now is 09:54 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting