Error when my program runs
I would greatly appreciate any help with my simple program. I am a begginner and I don't have much expierience. The program I wrote is closed by Windows due to an error when I try to run it after compiling. The "password" part isn't complete but I don't think it should make a difference. Another question I have is about using an instance of a function. I'm not sure how to assign a value to my strings. Please reply with a fix to my problem or any suggestions about changes I should make. (Sorry I was too lazy to make any in depth comments in my code yet)
Code:
//I'm writing this program to become more familiar with classes
//It's supposed to have a basic password thing and then give access to a calculator/average function
//I'm pretty sure the issue is in the startproc function
#include <fstream>
#include <iostream>
using namespace std;
class Calculator
{
public:
Calculator();
~Calculator();
void startproc (char user_pass[50], char pass[50] );
void average (int avnum, int total, int divisor, int answer, char YorN[2]);
};
Calculator::Calculator()
{}
Calculator::~Calculator()
{}
void Calculator::startproc (char user_pass[50], char pass[50])
{
ifstream pass_one ( "Pass1.txt" );
pass_one>> pass;
cout<< "Please enter the password to access this program.\n";
cin.getline ( user_pass, 50);
}
void Calculator::average (int avnum, int total, int divisor, int answer, char YorN[2])
{
while ( strcmp (YorN, "n") == 0)
{
cout<<"Please enter the number you would like to average.\n";
cin>> avnum;
total = total + avnum;
cout<<"Are you done entering numbers? (y or n)\n";
cin.getline(YorN, 2);
divisor = divisor + 1;
}
answer = total / divisor;
cout<<"The average of your numbers is..."<<answer;
cin.ignore();
}
int main()
{
Calculator functions;
functions.startproc(0, 0);
int option;
cout<<"Please select and action..\n";
cout<<"1) Average\n";
cin>> option;
switch (option)
{
case 1:
functions.average(0, 0, 1, 0, "null");
break;
default:
cout<<"Please select an option.";
cin.ignore();
}
}