Void functions

It's me again, I've already changed my program, but it still running wrong. Here's what I've done:
using namespace std;
#include<iostream>
#include<cmath>
#include<iomanip>
void locate(int&, int&, double& );
int main()
{ int more, less;
double N;
do
{ cout<<"Enter a value for N: ";
cin>>N;}
while (N>10 || N<0);
locate(more, less, N);
cout<<fixed<<right<<setprecision(2);
cout<<fixed<<right<<setw(8)<<"more"<<setw(10)<<"less"<<setw(20)<<"(more/N)*100%"<<endl;
cout<<fixed<<right<<setw(8)<<more<<setw(10)<<less<<setw(18)<<(more/N)*100<<endl;

system("pause");
return(0);
}
void locate(int& more, int& less, double& N)

{ double x;
ifstream indata("testdata.txt");
indata>>x;
if (x>0.7) more++;
if (x<0.6) less++;
}

And what it is supposed to do is:

Problem 2.57:
Write a C++ program which consists of a main function and a void function called locate ( int N, int& more, int& less).
The main function :
a. Reads from the keyboard a value for N ( between 1 and 10).
b. Calls the function locate.
c. Outputs to the screen the values of "more" and "less" with appropriate labels.
d. Outputs to the screen (lableled) the quotient of more divided by N, as a percentage.
The function locate reads 10 data values from a text file "testdata.txt", found by clicking here, then calculates and returns an integer "more", which is the number of entries read from the text file that are greater than 0.7, and an integer "less", which is the number of entries read from the text file that are less than 0.6.
0.351 0.659 0.901 0.136 0.432
0.835 0.547 0.470 0.211 0.965
---------------------------------------------
More and less assume faunny values, what can I do to solve my problem.
I am sorry if I didn't make myself clear the last time.
When you allocate data (like int more;) it is given the value that was in that memory location before the program had stared. To avoid this you must manually set its value to zero.
Last edited on
Topic archived. No new replies allowed.