Calculator problem

Hey.I am writing again,I put all my calculators thogether and it is pritty good:) But i have problem when i use one function(+ , - ,* , /) and when i finish calculating it close my program...But i want to cont. calclulating!! ^^

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
#include<iostream>
#define _WIN32_WINNT  0x0500
#include <windows.h>
#include <iostream>
using namespace std;

int main(){
int a,b,c,d,e,f;
 



cout<<"+=1 -=2  /=3  *=4  avar.=5"<<endl;
cout<<"Press any numbers from 1 to 5 to choose type of calculating"<<endl;
while(true) {


char character;
character=cin.get();

if(character=='1')
{
cout<<"Write first number:";
cin>>a;

cout<<"Write second number:";
cin>>b;

c=a+b;

cout<<"Your number is: "<< c <<endl;
if(cin.get()=='n') break;
}


if(character=='2')

{
cout<<"Write first number:";
cin>>a;

cout<<"Write second number:";
cin>>b;

c=a-b;

cout<<"Your number is: "<< c <<endl;
if(cin.get()=='n') break;
}




if(character=='5')



{
cout<<"Write two numbers that you want to get avarage"<<endl;

cin>>a;
cin>>b;
	
c=(a + b)/2;

cout<<"Your number is: "<<c<<endl;
if(cin.get()=='n') break;

}


if(character=='4')
{
	cout<<"Write first number(x)"<<endl;
	cin>>a;

	
	
	cout<<" * "<<endl;
	

	cout<<"Write second number(y)"<<endl;
	cin>>b;

	
	
	c=a*b;

		cout<<"x * y= "<< c <<endl;
if(cin.get()=='n') break;
}
system("pause");
return 0;
}
}




//this program is made with easy codes contected with pure logic:)//


Ty for help
could just put the whole program of main() in a do while loop, then at the end of the function have the user input 'y' or 'n' for whether they want to run again.
can you give me example of do while loop?
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
   do{
   //code code
  }while(/*condition*/)
  //before the system pause (where your if loop currently is)

}


I however prefer to just use a while loop... basically you just don't do the do part, and state the condition in the beginning (which prevents confusion)

for more info on loops read: http://cplusplus.com/doc/tutorial/control/

Cheers!
Last edited on
You don't put a condition after do !!!
oh yeah, sorry...
Topic archived. No new replies allowed.