How to start from beginning of the program

前端 未结 6 1732
灰色年华
灰色年华 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:10

    The following code will do that:

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

    above code will run forever. If you want to give user a choice, then apply a loop break condition.

      char repeat = 'y';
      while( repeat == 'y'){
    
      // do as previous
    
      //.....
    
     //finally give user a choice
    
      cout<< "Do you want to repeat?(y/n):";
      cin>> repeat;
      }
    
    
        system("pause");    
    }
    

提交回复
热议问题