Help with Functions

It keeps telling me im using local unintialized variables in main. When I thought I assigned them a value


#include<iostream>
#include<fstream>
using namespace std;

//prototypes
void Openfile();
int readFile(int number,int inputfile);
void Determine(int &number);
void Display(int e);
int main()
{
int number;
int inputfile;
int e;

Openfile();
//number = readFile (number, inputfile);
Determine(number);
Display(e);
system("pause");
return 0;
}

//*************
//will open the file
void Openfile()
{

ifstream inputfile;
inputfile.open("easy.txt");
}

//*********************
//This will read in data from file
//*********************
int readFile(int number,int inputfile) {
while(inputfile >> number);
return number;
return inputfile;
}
//***********
//determine values/
//**************
void Determine (int &number)
{
int e=0, o=0, zero=0;

if (number % 2 == 0)
e++;
else
o++;
if (number == 0)
zero++;
}

//****************
void Display(int e)
{
cout << "number of even numbers is" << e;
}
your main, with some stuff removed, to show the problem.

int main()
{
int inputfile;
int e;
Display(e); //uninitialized.
return 0;

but that is the tip of the iceberg. Inputfile is also not initialized. It looks like you think 'openfile' does something. It does nothing. (Ok, not 100% accurate, it opens a local file variable that is then destroyed when the function exits). Using the same variable name does NOT mean its the same variable. Its just making it confusing for the reader to reuse them. You need to pass in the file variable or return one:

void Openfile(ifstream %infile) //like this

and call it
Openfile(inputfile);

then it will do what you think it is doing.
there are similar issues throughout.
Last edited on
im having a problem with this program :

Create a .cpp program that verifies the strength of a password that a user is entering is strong (complex/secure) enough. In the main area of the program, prompt the user to enter a password. Then, call a function, passing into it the password that they entered.
In the function, use whatever .cpp commands or built-in functions are available to ensure:
a. The password is at least 8 characters in length.
b. The password is mixed case (upper and lower).
c. You have at least one of these valid special characters in your password:
$ ! @ % ^ & * #
The function will determine if the password is strong enough and then output the correct message. Here is a sample run and output from the program:

First Run:
Enter a password: thisis
Your password length is too short. Please choose a password that is at least 8 characters long.
Your password is not a mixed case. Please choose a password with mixed case.
You do not have a valid special character in your password. Please add at least one special character.

Second Run:
Enter a password: thisismypassword
Your password is not a mixed case. Please choose a password with mixed case.
You do not have a valid special character in your password. Please add at least one special character.

Third Run:
Enter a password: Thisismypassword
You do not have a valid special character in your password. Please add at least one special character.

Fourth Run:
Enter a password: thisis!myPassWORD
Thank you. Your password is valid.
Samhm313,

Please, create a new thread with your issue. Thanks for your time.

Respectfully,

chicofeo
Topic archived. No new replies allowed.