View Single Post
Old Apr 26th, 2008, 3:56 PM   #8
Marijan
Newbie
 
Join Date: Feb 2008
Posts: 15
Rep Power: 0 Marijan is on a distinguished road
Re: Returning to the main function from another

Thanks for the detailed explanation it really helped me to understand it better so i reconstructed my code and compiled it again so it would be like this,the whole program is not written,but this is the important part i need help on.As you can see i changed using the advice i got but it won't return me to the main function when i say so.

<c++> Syntax (Toggle Plain Text)
  1.  
  2.  
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. #include <stdlib.h>
  7.  
  8.  
  9. using namespace std;
  10.  
  11. void Sobiranje()
  12. {
  13. float v_broj,rezultat=0;
  14.  
  15. system("cls");
  16.  
  17. cout<<endl;
  18. cout<<" ---------------------------------"<<endl;
  19. cout<<" ***** Marijan's Claculator *****"<<endl;
  20. cout<<" ---------------------------------"<<endl;
  21. cout<<endl;
  22. cout<<endl;
  23. cout<<endl;
  24.  
  25. float broj,a,broj_nasob;
  26. cout<<"Insert the numbers you would like me to calculate,to return to the main menu press 0 :"<<endl;
  27.  
  28. while(broj!=0)
  29. {
  30. cin>>v_broj;
  31. if(v_broj!=0) //If the number you insert is not 0
  32. rezultat=rezultat+v_broj;//keep adding them all
  33. else //if it is 0
  34. return; //Get back to the main function to start it all over
  35.  
  36.  
  37.  
  38. cout<<"Rezultatot e :"<<rezultat<<endl;
  39. }
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45. int Izbor=0;
  46.  
  47.  
  48.  
  49. cout<<endl;
  50. cout<<" ---------------------------------"<<endl;
  51. cout<<" ***** Marijan's Calculator *****"<<endl;
  52. cout<<" ---------------------------------"<<endl;
  53.  
  54. cout<<endl;
  55. cout<<endl;
  56. cout<<" *-------------------------------------------------*"<<endl;
  57. cout<<" |1.For addiction of two or more numbers select 1|"<<endl;
  58. cout<<" |2.For subtraction select 2| "<<endl;
  59. cout<<" |3.For multipication select 3|"<<endl;
  60. cout<<" |1.For division select 4|"<<endl;
  61. cout<<" *-------------------------------------------------* "<<endl;
  62. cout<<"Izbor :"<<endl;//Means "choice"
  63. cin>>Izbor;//enter your choice
  64. if(Izbor==1)//if you choose 1
  65. Sobiranje();//run the Sobiranje function(addition)
  66.  
  67.  
  68. system("PAUSE");
  69. return 0;
  70.  
  71.  
  72. }


And yet it won't return me to the original menu,instead when i press 0,press any key to continue appears.

P.Corry for being annoying.
Marijan is offline   Reply With Quote