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!! ^^
#include<iostream>
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
usingnamespace 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:)//
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.
#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)