C++ help in setting up a function?
-
how do i write this in c++ just need help to figure it out Write a C++ program that uses, in addition to the 'main()' function, three additional functions called: DemonstrateAForAndWhileLoop() DemonstrateForLoop() DemonstrateWhileLoop() The first of these three functions does not return any value to the calling function. The last two of these three functions both return an 'int' value to the calling function. Declare the function prototypes for these three functions above the 'main()' function. --------------------- In the 'main()' function just call the first of the above three functions, and then include the standard return statement for the 'main()' function. --------------------- In the 'DemonstrateAForAndWhileLoop()' function, declare a variable to store how many positive numbers the user has entered. Initialize this variable to 0. Then increment this variable by the return value that you get by calling the 'DemonstrateForLoop()' function. Then increment this variable by the return value that you get by calling the 'DemonstrateWhileLoop()' function. Then print out how many positive numbers the user has entered In the 'DemonstrateForLoop()' function declare a variable to store the number of positive integers that the user has entered in this function so far. Declare any other variables that you need in order to store an integer that the user enters, and a sum of the positive integers that the user has entered. Define a 'for' loop that is set up to execute 5 times. Declare the index variable for the 'for' loop above the 'for' loop. Initialize all of the variables that you have declared that you need to initialize to their correct initial values in the "initialization" part of the 'for' statement. On each iteration ask the user to enter a positive integer, and read in and store what the user enters. If the user has entered a non-positive integer, then use a 'continue' statement to immediately go on to the next iteration of the 'for' loop. Otherwise, increment the variable that stores the number of positive integers that the user has entered in this function so far, and then, if the sum of the positive integers that the user has entered so far is greater than 100, use a 'break' statement to exit from the 'for' loop. After the 'for' loop, print out the sum of the positive integers that the user entered, and then return the the number of positive integers that the user entered in this function as the "return value" from the function. In the 'DemonstrateWhileLoop()' function, declare a variable to count how many positive numbers the user has entered so far, and initialize this variable to 0. Declare and initialize (if necessary) any other variables that you need in order to store an integer that the user enters, and a sum of the positive integers that the user has entered. Then define a 'while' loop that only executes if the sum of the positive integers that the user has entered so far (in the 'DemonstrateWhileLoop()' function) is less than or equal to 100. On each 'while' loop iteration, ask the user to enter a positive integer, and read in and store what the user enters. If the user has entered a non-positive integer, then use a 'continue' statement to immediately go on to the next iteration of the 'while' loop. Otherwise, increment the sum of the positive integers that the user has entered, and increment the variable counting how many positive numbers the user has entered so far. After the 'while' loop, print out the sum of the positive integers that the user entered, and then return the the number of positive integers that the user entered in this function as the "return value" from the function. --------------------- just need help setting it up thanks
-
Answer:
int DemonstrateForLoop(){ int count=0, sum=0; for(int i=0;i<5;i++) { int N; cin>>N; if(N<0) continue; count++; sum+=N; if(sum>100) break; } cout<<sum<<endl; return count; } int DemonstrateWhileLoop(){ int count=0, sum=0; while(1) { int N; cin>>N; if(N<0) continue; count++; sum+=N; if(sum>100) break; } cout<<sum<<endl; return count; } DemonstrateAForAndWhileLoop(){ int count=0; if(DemonstrateForLoop())count++; if(DenonstrateWhileLoop())count++; cout<<count<<endl; }
Abi at Yahoo! Answers Visit the source
Related Q & A:
- What Is The Geometric Meaning Of Third Derivative Of A Function At A Point?Best solution by Mathematics
- How to pass a parameter to a function that is called on an event?Best solution by Stack Overflow
- how to call a function in Python in another function?Best solution by Yahoo! Answers
- Does anyone know how id go about setting up a soccer management simulation game site to run as a business?Best solution by Yahoo! Answers
- Setting up a printer to my mac?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.