While loop is not working

I am writing a program for mcdonald ordering system, now I extracted one part of my program. I don't know why the while loop is not working, it just runs once.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include<iostream>
using namespace std;
int n[9];
int main(){
cout<<"(A)How many of Chicken McNuggets(s) you want to order(at least 4)? ";cin>>n[0];
	while(n[0]>0){
	if (n[0]>=4 && (n[0]%6==0||n[0]%9==0 ||(n[0]>=15 && n[0]%3==0 ))){
			if(n[5]>=2 && n[6]>=2){					
				if(n[0]%6==0)
				{size[c]=n[0]/6;m1=1;}
				else if((n[0]-9)%6==0 )
				{size[c]=(n[0]-9)/6;m1=1;}
				else if(n[0]%15==0)
				{size[c]=(n[0]/15);m1=1;}
				else if(n[0]==9)
					{size[c]=(n[0]/9);m2=1;}
				if(size[c]>n[5]/2 && size[c]>n[6]/2)	{
					if(n[5]>n[6])
						size[c]=n[6]/2;
					else
						size[c]=n[5]/2;     }
				    n[5]-=size[c]*2;
			        n[6]-=size[c]*2;        }
			else{
				if(n[0]%6==0)
				{size[c]=n[0]/6;a1=1;}
				else if((n[0]-9)%6==0 )
				{size[c]=(n[0]-9)/6;a1=1;}
				else if(n[0]%15==0)
				{size[c]=(n[0]/15);a1=1;}
				else if(n[0]==9)
				{size[c]=(n[0]/9);a2=1;}}
			if(m1){	
		    price[c]=size[c]*22;
			type[c]="M1";	
			n[0]-=size[c]*6;}
			if(m2){
            price[c]=size[c]*35.5;
			type[c]="M2";
			n[0]-=size[c]*9;}
			if(a1){
		    price[c]=size[c]*17.5;
			type[c]="A1";
			n[0]-=size[c]*6;
			}
			if(a2){
		    price[c]=size[c]*22.8;
			type[c]="A2";
			n[0]-=size[c]*6;
			}
			c++;
	}  
			
		else solved=0;break;}
return 0;
}
closed account (z05DSL3A)
Does it even compile?

EDIT:...
but anyway, the problem is likely with the line (54) else solved=0;break;}. I suspect you want something like

1
2
3
4
5
6
7
//...
   else
   {
        solved = 0;
        break;
    }
}

as it is it will break on the first run.
Last edited on
closed account (48T7M4Gy)
 In function 'int main()':
10:6: error: 'size' was not declared in this scope
10:11: error: 'c' was not declared in this scope
10:21: error: 'm1' was not declared in this scope
12:6: error: 'size' was not declared in this scope
12:11: error: 'c' was not declared in this scope
12:25: error: 'm1' was not declared in this scope
14:6: error: 'size' was not declared in this scope
14:11: error: 'c' was not declared in this scope
14:24: error: 'm1' was not declared in this scope
16:7: error: 'size' was not declared in this scope
16:12: error: 'c' was not declared in this scope
16:24: error: 'm2' was not declared in this scope
17:8: error: 'size' was not declared in this scope
17:13: error: 'c' was not declared in this scope
22:15: error: 'size' was not declared in this scope
22:20: error: 'c' was not declared in this scope
26:6: error: 'size' was not declared in this scope
26:11: error: 'c' was not declared in this scope
26:21: error: 'a1' was not declared in this scope
28:6: error: 'size' was not declared in this scope
28:11: error: 'c' was not declared in this scope
28:25: error: 'a1' was not declared in this scope
30:6: error: 'size' was not declared in this scope
30:11: error: 'c' was not declared in this scope
30:24: error: 'a1' was not declared in this scope
32:6: error: 'size' was not declared in this scope
32:11: error: 'c' was not declared in this scope
32:23: error: 'a2' was not declared in this scope
33:7: error: 'm1' was not declared in this scope
34:7: error: 'price' was not declared in this scope
34:13: error: 'c' was not declared in this scope
34:16: error: 'size' was not declared in this scope
35:4: error: 'type' was not declared in this scope
37:7: error: 'm2' was not declared in this scope
38:13: error: 'price' was not declared in this scope
38:19: error: 'c' was not declared in this scope
38:22: error: 'size' was not declared in this scope
39:4: error: 'type' was not declared in this scope
41:7: error: 'a1' was not declared in this scope
42:7: error: 'price' was not declared in this scope
42:13: error: 'c' was not declared in this scope
42:16: error: 'size' was not declared in this scope
43:4: error: 'type' was not declared in this scope
46:7: error: 'a2' was not declared in this scope
47:7: error: 'price' was not declared in this scope
47:13: error: 'c' was not declared in this scope
47:16: error: 'size' was not declared in this scope
48:4: error: 'type' was not declared in this scope
51:4: error: 'c' was not declared in this scope
54:8: error: 'solved' was not declared in this scope
 


Getting it to run even once would be a bonus.
Last edited on
cause I only extracted one part of the whole coding so thats why i forgot to include those initializations
And the problem really exists in else solved=0;break;}. Thanks!
Topic archived. No new replies allowed.