Why is my program not breaking the loop?

it seems to loop even when i dont want it to

Page 1 of 1

3 Replies - 531 Views - Last Post: 03 July 2009 - 04:04 AM Rate Topic: -----

#1 Pipey85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 30-June 09

Why is my program not breaking the loop?

Post icon  Posted 03 July 2009 - 01:51 AM

Ok first, ive changed some the text as some of you lovelly people may find it offensive, this is my first attempt at something like this in terms of size, it just seems that the statements that are pointed out just keep looping even when i try to break the loop.

#include "stdafx.h"
#include <iostream>
using namespace std;

int c1smoke(int xp);
int c1save(int xp);


void GO ();

int main()
{	
	int RampagePoints =0;
	int xp = 0;
	int DChoice;
	bool start = true;
	char strt, BC;



	while (start == true)
	{		
	start = false;
		cout << "please choose an option\n\n";
		cout << "1.number1\n2.number2\n3.number3\" << endl;
		cin >> DChoice;
		cout << endl << endl;

	switch (DChoice)
	{


		case 1:
			{
		int choice1;
		bool cse1strt = true
		;
		while (cse1strt = true)	// this loop here keeps going eveytime i make a choice from the point
		{								 // marked "point !"
			cse1strt = false;
		cout << "You do something....... gaining 1 xp";
		++xp;
		cout <<	"\n Now Do you\n1.do this\n2.do that?\n";
		cin >> choice1;

			switch (choice1)
			{
		case 1: //inside switch (choice1)
			{
				xp = c1smoke (xp);
				cse1strt = false;
				break;			   \\ Point ! why is it doing this?
			}
		case 2:
			{
				c1save (xp);
				break;
			}
		default:{
			cout << "That's not an option, try again!";
			cse1strt = true;
			break;
				}
			} // end of switch (choice1)

		
		} // end of while cse1strt
			}//end of case1
		case 2:
	{
		cout << "not got this far\n\n\n";
		++xp;
		break;
	}
		case 3:
	{
		cout << "coming soon\n\n\n";
		++xp;
		break;
	}
				default:
	{
		cout << "Are you high? That wasnt an option!\n";
	}
	
	

	cout << endl << "total xp = " << xp;
	cout << endl << "Would you like to try a different drug?";
	cin >> strt;

	if (strt == 'y' || 'Y')
	{
		cout << endl << endl << endl;
		start = true;
	}
	else
		start = false;



	} // end of switch
	return 0;
	}// end of while start
}//end of main

void GO ()
{
	cout << "GAME OVER!!";
}
int c1smoke(int xp)
{
char any;
	cout << "YAY  >>> you gain 1 xp";
	++xp;

	
	return xp;





}//end of c1smoke


int c1save(int xp)
{
	return xp;
}



I hope its not to difficult to understand beacause of the text edits, but i really dont want to offend anybody.

so any ideas as to why the loop wont break when i ask it to? thanks in adavnce guys (and gals) im sure this is no match for your mighty knowledge :P

Is This A Good Question/Topic? 0
  • +

Replies To: Why is my program not breaking the loop?

#2 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: Why is my program not breaking the loop?

Posted 03 July 2009 - 02:34 AM

case 1: //inside switch (choice1)
{
	xp = c1smoke (xp);
				 cse1strt = false;
				break;			  
}




This break point takes you out of your switch not your while loop,

default:{
	cout << "That's not an option, try again!";
	cse1strt = true;
	break;
	}

} // end of switch (choice1)

break;



Add this extra break point to allow you to exit the while loop.

Hope this helps
Kevin :)

This post has been edited by deery5000: 03 July 2009 - 02:36 AM

Was This Post Helpful? 1
  • +
  • -

#3 Pipey85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 30-June 09

Re: Why is my program not breaking the loop?

Posted 03 July 2009 - 03:39 AM

Thanks kevin, thats spot on :D you earned yourself a thankyou.

The thought of using an extra break statement never crossed my mind, because I was trying to set the control statement to false, but as I found out it doesn't work :P

Thanks again Kevin :)
Was This Post Helpful? 0
  • +
  • -

#4 deery5000  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 966
  • Joined: 09-May 09

Re: Why is my program not breaking the loop?

Posted 03 July 2009 - 04:04 AM

Glad i coud help mate :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1