Can someone quick tell me why this wont run?

This is driving me insane. I had it running earlier but accidentally saved over top of it so I redid it and now its not working. I cant for the life of me find out why.

Thanks, Jeremy.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  //Lab 3-1: Print out the values of square root of all 
//integers divisible by 5 between 5 and 100.

#include <iostream>
#include <math.h>
using namespace std;

void print();

int main()
{

	for (int i = 5; i <= 100; i += 5){

		print();

	}

	cin.get();
	return 0;

}

void print()
{

	cout << "The square root of " << i << " is " << sqrt(i) << "." << endl;

}
cout << "The square root of " << i << " is " << sqrt(i) << "." << endl
where is i coming from?

test.cpp: In function 'void print()':
test.cpp:27:35: error: 'i' was not declared in this scope


I think your function should be
1
2
3
4
void print(int i)
{
   cout << "The square root of " << i << " is " << sqrt(i) << "." << endl;
}

Dont forget to edit the declaration.
Now it says too few arguments in function call and 'print' function does not take 0 arguments.
Are you sure that's right?
yes ofcourse, there is actually too few arguments if you call the function in main without its argument list.
Your call in line 15 should be print(i)
Lol oh boy now its telling me print function does not take 1 argument.
Ok nevermind I got it. Thank you so much for all of your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

//Lab 3-1: Print out the values of square root of all 
//integers divisible by 5 between 5 and 100.

#include <iostream>
#include <math.h>
using namespace std;

void print(int i);

int main()
{

	for (int i = 5; i <= 100; i += 5){

		print(i);

	}

	cin.get();
	return 0;

}

void print(int i)
{

	cout << "The square root of " << i << " is " << sqrt(i) << "." << endl;

}
Topic archived. No new replies allowed.