![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Feb 2008
Posts: 15
Rep Power: 0
![]() |
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. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Call the class main function | quantalfred | Java | 6 | Jul 23rd, 2006 1:38 PM |
| Recommended Practice for returning data from function | Arla | C# | 1 | Aug 16th, 2005 12:21 PM |
| Returning a value from a variable to the main function | colt | C | 3 | Apr 28th, 2005 7:56 AM |
| Problem when returning a string from a function in VC++ | vjkancha | C++ | 10 | Mar 7th, 2005 1:18 PM |
| Returning An Array From a Function | ViZioN | C++ | 5 | Feb 21st, 2005 6:45 PM |