How to start from beginning of the program

前端 未结 6 1783
灰色年华
灰色年华 2021-01-17 02:00

I am a very beginner in c++. i am just learning abc of this language.. i created this small program that would add:

#include 
   using namesp         


        
6条回答
  •  盖世英雄少女心
    2021-01-17 02:18

    If we were to take "start from the beginning" literally, we can call main() again when we get to the end!

    #include 
       using namespace std;
    
    float add(float a, float b){
                  return a+b;  
          }
    
    int main(){
    
        float num1;
        float num2;    
    
        cout<<"add...enter digits \n";
        cout<<"first digit: ";
        cin>>num1;
        cout<<"\n Second number: ";
        cin>>num2;
    
        cout<< "your sum is: "<

    (This will eventually crash when the program runs out of stack space, but the user will almost certainly get tired of adding numbers long before then. Of course, a clever compiler would realize this is tail recursion, and use a goto instead of a function call.)

提交回复
热议问题