How Can i Change my Terminator in While Loop

I Want to Change my Terminator from 0 to = . . when i put '=' my program is error. . :( im so very beginner in c++ so pls help me guys

please help me!


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdio.h>
#include<stdlib.h>


main()
{
    int iNum1,iNum2, iNum3; /*1st Integer Number*/
    int iSum, iSum2, iSum3; /*Addition*/ 
    int iDiff, iDiff2, iDiff3; /*Subtraction*/
    int iPro, iPro2, iPro3; /*Multiplication*/   
    float iQuo, iQuo2, iQuo3; /*Division*/      
    int cOp=0; /*Operations*/
    printf("===============================================================================\n");
    printf("\n\t\t\t\t<<Menu>> \n");
    printf("\n===============================================================================\n\n");
	printf("Choose the Operation that you want to use! Just Press the Number then Enter\n\n");
	printf("[1] Addition (+) Operation\n");
	printf("[2] Subtraction (-) Operation\n");
	printf("[3] Multiplication (*) Operation\n");
	printf("[4] Division (/) Operation\n");
	printf("[0] To Get the Answer / Terminate the Program\n\n");
    printf("===============================================================================\n\n");
      
	printf("Enter your Operation : ");
	scanf("%d", &cOp);
    printf("\n===============================================================================\n\n");

	switch(cOp){
		case 1:
            printf("Your Operation is Addition\n");
			printf("\nEnter 1st Addend Number: ");
			scanf("%d", &iNum1);
			printf("Enter 2nd Addend Number: ");
			scanf("%d", &iNum2);
			iSum = iNum1;

			while(iNum2 != 0){
			iSum = iSum + iNum2;
			printf("Enter Another Addend Number: ");
			scanf("%d", &iNum2);
			}
			printf("\nThe Sum is %d\n", iSum);
			break;

		case 2:
            printf("\nYour Operation is Subtraction\n");
			printf("\nEnter Minuend Number: ");
			scanf("%d", &iNum1);
			printf("Enter Subtrahend Number: ");
			scanf("%d", &iNum2);
			iDiff = iNum1;
			
			while(iNum2 != 0){
			iDiff = iDiff - iNum2;
			printf("Enter Another Subtrahend Number: ");
			scanf("%d", &iNum2);
			}
			printf("\nThe Difference is %d\n", iDiff);
			break;

		case 3:
            printf("\nYour Operation is Multiplication\n");             
			printf("\nEnter Factor Number: ");
			scanf("%d", &iNum1);
			printf("Enter Another Factor Number: ");
			scanf("%d", &iNum2);
			iPro = iNum1;
			
			while(iNum2 != 0){
			iPro = iPro * iNum2;
			printf("Enter Another Factor Number: ");
			scanf("%d", &iNum2);
			}
			printf("\nAnswer : The Product is %d\n", iPro);
			break;

		case 4:
            printf("\nYour Operation is Division\n");             
			printf("\nEnter Dividend Number: ");
			scanf("%d", &iNum1);
			printf("Enter Divisor Number: ");
			scanf("%d", &iNum2);
			iQuo = iNum1;
			
			while(iNum2 != 0){
			iQuo = iQuo / iNum2;
			printf("Enter Another Divisor Number: ");
			scanf("%d", &iNum2);
			}
			printf("\nAnswer : The Quotient is %.2f\n", iQuo);
			break;

		default:
			printf("\nOpss. . . Error!!! hehehehe ^_^v\n");
			printf("Please Don't Force It. . . \n\n");
			break;
	}
    printf("\n===============================================================================\n\n");

	printf("Choose your previous operation that you use\n\n");
	printf("[1] Addition (+) Operation\n");
	printf("[2] Subtraction (-) Operation\n");
	printf("[3] Multiplication (*) Operation\n");
	printf("[4] Division (/) Operation\n");
	
	printf("\nWhat is your Previous Operation that you use  ");
	scanf("%d",&cOp);
    
    switch (cOp){
           case 1:
                  printf("\nYour Previouse Operation is Addition\n");
                  iSum2=iSum;
                  printf("Previous Answer Addition is %d\n",iSum2);
           break;
           
           case 2:
                  printf("\nYour Previouse Operation is Subtraction\n");
                  iDiff2=iDiff;
                  printf("Previous Answer Subtraction is %d\n",iDiff2);
           break;
                             
           case 3:
                  printf("\nYour Previouse Operation is Subtraction\n");
                  iPro2=iPro;
                  printf("Previous Answer Multiplication is %d\n",iPro2);
           break;                  
           
           case 4:                                   
                  printf("\nYour Previouse Operation is Division\n");
                  iQuo2=iQuo;
                  printf("Previous Answer Division is %d\n",iQuo2);  
           break;                  
                  
                                  
                  }
    
    
    
                


   printf("\n===============================================================================\n\n");
   
   printf("Thank You for Using My Continuous Calculator Program. . . \n");
   printf("Godbless You. . . .\n\n");
   
system("PAUSE");
getchar();

}
I do not get you can you please explain, or show an example, or the line in which you want the change?
You don't have a while loop in here.

For instructions on how to use while loops take a look at this tutorial:
http://cplusplus.com/doc/tutorial/control/
@stewbond: but i don't see that he doesn't have a control structure, instead, the control structure is not really obvious and can lead to a bug... like this:
1
2
3
4
5
while(iNum2 != 0){
iSum = iSum + iNum2;
printf("Enter Another Addend Number: ");
scanf("%d", &iNum2);
}

CMIIW
Oh I see,

Then add this to your switch statement:
1
2
case '=':
    return 0;


That will exit your program when '=' is pressed.
@Stewbond also i want is ! when i press '=' the answer will show on the program !

u have an idea how to solve my problem?

when i put '=' my program is running like this :D also another case function :D

so i need your help :( syntax error :D

http://i972.photobucket.com/albums/ae202/trisha000/1-6.png
Last edited on
Use cin.sync();
In case 2:

1
2
3
4
5
6
while(iNum2 != 0){
			iSum = iSum + iNum2;
			printf("Enter Another Addend Number: ");
			scanf("%d", &iNum2);
                        cin.sync();   //this is to clear the buffer
			}
@Aceix how can i change my terminator/getting then final answer using '='
Then I suggest you make c0p a char so that you can make a switch case to check for = eg:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
char input;     //replace input with c0p

cout<<"1. Do you want to laugh?";   //cout works like printf--I programme in C++
cout<<"\n2. Do you want to cry?";
cout<<"\n\'=\' To display my status whiles programming.";
cout<<"\n\nSelection: ";
cin>>input;     //cin works like scanf

switch(input)
{
     case 1:
       ........
     case 2:
       .........
     case '=':        //note the single quotation marks, to tell the compiler it is a character not an operator
       cout<<"\n\nHappy!!!";
       break;
     default:
       ..........
}


Hope it helps!
Last edited on
Topic archived. No new replies allowed.