Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 26th, 2008, 7:06 AM   #1
Marijan
Newbie
 
Join Date: Feb 2008
Posts: 15
Rep Power: 0 Marijan is on a distinguished road
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.
Marijan is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC