|
Returning to the main function from another
As the tittle says i want my program to return to the main() from another function if a certain condiction is true.Here is the code:
[code=c++]
#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 0
return main();//Get back to the main function to start it all over
else
rezultat=rezultat+v_broj;
cout<<"Rezultatot e :"<<rezultat<<endl;
return main();
}
int main()
{
int Izbor=0;
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;
cin>>Izbor;
if(Izbor==1)
Sobiranje();
system("PAUSE");
return 0;
}
[\code]
But some problems appear when i try to compile it,first it says to use the main function first and i do so,then it says something else.I am a tottal begginer in C++ so don't get angry if i have mistaken some simple things.Thanks in advance.
|