help with uninitialized local variable

I'm having trouble debugging this, im sure that im initializing 'r' on line 11.


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
32
#include <iostream>
#include <iomanip>
using namespace std;
int radius(int);
void both(int&, int&, int&);

int main()
{
	int c, r, a;
	cout << "Hi there!" << endl;
	r = radius(r);
	both(a,c,r);
	cout << "The Circumference is: " << c << endl;
	cout << "The Area is: " << a << endl;
	return 0;
}

//gets radius
int radius(int r)
{
	cout << "Enter a radius: ";
	cin >> r;
	return r;
}

//gets circ and area
void both(int& a, int& r, int& c)
{
	r = radius(r);
	c = 2 * (3.14) * r;
	a = 2 * (3.14) * r * r;
}
Last edited on
closed account (j3Rz8vqX)
Integer data types is causing you issues:
1
2
3
	r = radius(r);
	c = 2 * (3.14) * r;
	a = 2 * (3.14) * r * r;


6=6.00=2*3.14*1; the decimal placed values are truncated.

Use floats or doubles.

6.28=2*3.14*1;

float c, r, a;

Now you can delete line 11 or 29; your choice.

Have a good day.
Topic archived. No new replies allowed.