#include <iostream>
#include <cmath>
#include <stdlib.h>
using namespace std;
void Sobiranje()
{
float v_broj,rezultat=0;
system("cls");
cout<<endl;
cout<<" ---------------------------------"<<endl;
cout<<" ***** Marijan's Claculator *****"<<endl;
cout<<" ---------------------------------"<<endl;
cout<<endl;
cout<<endl;
cout<<endl;
float broj,a,broj_nasob;
cout<<"Insert the numbers you would like me to calculate,to return to the main menu press 0 :"<<endl;
while(broj!=0)
{
cin>>v_broj;
if(v_broj!=0) //If the number you insert is not 0
rezultat=rezultat+v_broj;//keep adding them all
else //if it is 0
return; //Get back to the main function to start it all over
cout<<"Rezultatot e :"<<rezultat<<endl;
}
}
int main()
{
int Izbor=0;
while ( true ) {
cout<<endl;
cout<<" ---------------------------------"<<endl;
cout<<" ***** Marijan's Calculator *****"<<endl;
cout<<" ---------------------------------"<<endl;
cout<<endl;
cout<<endl;
cout<<" *-------------------------------------------------*"<<endl;
cout<<" |1.For addiction of two or more numbers select 1|"<<endl;
cout<<" |2.For subtraction select 2| "<<endl;
cout<<" |3.For multipication select 3|"<<endl;
cout<<" |1.For division select 4|"<<endl;
cout<<" *-------------------------------------------------* "<<endl;
cout<<"Izbor :"<<endl;//Means "choice"
cin>>Izbor;//enter your choice
if(Izbor==1)//if you choose 1
Sobiranje();//run the Sobiranje function(addition)
}
system("PAUSE");
return 0;
}
The problem you were having is that when your Sobiranje() function was returning to main(), the program quickly finished because there was nothing else to do.
What I've done in the above is inserted a
while loop that runs forever. When you return from the function, the while loop will make the program execute from the beginning of the loop again.