help me for char==??

help me for line 22? char==??? to break the loop????????

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
57
58
59
60
61
62
63
64
65
66
67
 #include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	float m;
	char f;
float a1=2.98;
float a2=4.50;
float a3=9.98;
float a4=4.49;
float a5=6.78;
float total=0;

for(int i=0;;i++)
{

cout<<"enter number of production"<<endl;
cin>>f;
cout<<"enter number of sales"<<endl;
cin>>m;
if(f==quit)
{ 
break;
}


switch(f)
{
case'1':
	total=a1+total;
	total=total*m;
	break;


	case'2':
	total=a2+total;
	total=total*m;
	break;


	case'3':
	total=a3+total;
	total=total*m;
	break;


	case'4':
	total=a4+total;
	total=total*m;
break;

	case'5':
	total=a5+total;
	total=total*m;
	break;


}
}

cout<<endl;
cout<<total;
getch();
return 0;

}
Last edited on
Your approach is not the best solution but anyway try this:
1
2
3
4
if(f=='q')
{ 
break;
}
ty. i know its not the best solution. i just trainning different ways .

ty so much :).

but why cant use f=='quit' ????????
Because char variables holds single characters: a,b,c,d,e,r etc
string variables holds words like "Hello","quit","Green"..etc.
appreciate that. ty ty ty :)
You are welcome!
@mohsenios
can you help to me?
allow private messages
in your account settings!
Another tip would be to use descriptive variable names and not one letter abbreviations like in math. This makes it a lot easier for the next person to look at your code to quickly understand what is happening especially if you are in a group project.
@eyenrique i do it :) if i can help you i do it


@giblit. ty for your notes. i remember it ... ty :)
Topic archived. No new replies allowed.