FUNCTION CHECK HELP PLEASE

This is what i have for this function so far but im pretty sure its wrong. can someone check it for me or tell me what it should look like if i did it wrong?

"write a function named print_range() that takes two INT arguments, start and stop and returns nothing. The function prints all of the numbers between strt and stop including start and stop. You can assume that start is less than or equal to stop"

VOID print_range()
{
int start = 3;
int stop = 5;

while(start >= 3)
{
if(stop <= 5)
{
cout << "your range is"; <<endl;
cout << "3"; <<endl;
cout << "4"; <<endl;
cout << "5"; <<endl;

return 0;
}

}
return;

}
Last edited on
write a function named print_range() that takes two INT arguments, start and stop


This statement states that you must make a function that takes arguments (arguments are placed inside the parenthesis):

1
2
3
4
void print_range(int start, int stop)
{
...
}


returns nothing


The point of it being void is so it does not return a value (no return is needed).

The function prints all of the numbers between strt and stop including start and stop. You can assume that start is less than or equal to stop


This could be done simply with either a while loop or for loop to print out each number within the function.

1
2
3
4
5
while(start <= stop)
{
...
start++;
}

OR
1
2
3
4
for(int i = start; i <= stop; i++)
{
...
}
if the function is supposed to take two argument you give it two argument.

and if you are using void function asking for a return would create an error.

@crimsonzero2 explained it very well.

1
2
3
4
5
cout<<"your range is: ";
for(int i = start; i <= stop; i++)
{
cout<< i<<endl;
}
Thank you very much, so can you show me what this looks like all together for example print_range(3,5)
@lonelylense
Thank you for saying that I explained it very well.

@mrahim9
All the piece are there between what lonelylense and I typed. All you have to do is piece it together and it would work.
got it..thanks guys @lonelylense @crimsonzero2
sure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int print_range(int start, int stop)
{
for(int i = start; i <stop; i++)
     {
            cout<< i<<endl;
     }
return stop;
}

int main(){

   cout<<print_range(3,5)<<endl;

   return 0;
}
Topic archived. No new replies allowed.