ATM program help...

I need some help with my atm program. I don't remember how to inFile. I need to use that so that the users who log in are saved onto the program for future use. The program opens but when I select an option, it gives me an error saying "value2" is being used without being initialized. If there are anymore errors, could you please point them out.

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <fstream>
using namespace std;

int main()

{
	cout << "       ///    /// //////// ///     //////// //////// ///    /// ////////\n";
	cout << "      ///    /// ///      ///     ///      ///  /// ////////// ///\n";
  	cout << "     /// // /// ///////  ///     ///      ///  /// /// // /// ////////\n";
	cout << "    ////////// ///      ///     ///      ///  /// ///    /// ///\n"; 
	cout << "     /// ///  //////// /////// //////// //////// ///    /// ////////\n";
	cout << "                            //////// ////////\n";
	cout << "                              ///   ///  ///\n";
	cout << "                             ///   ///  ///\n";
	cout << "                            ///   ///  ///\n";
	cout << "                           ///   ////////\n";
	cout << "                       ////////\n";
	cout << "                      ///        ///      ///\n";
	cout << "                     ///      //////// ////////\n";
	cout << "                    ///        ///       ///\n";
	cout << "                   ////////\n";
	cout << "               ///////     ///    ///   /// ///  ///\n";
	cout << "              ///   /// ///  /// ///// /// /// ///\n";
	cout << "             ////////  //////// /// ///// /////\n";
	cout << "            ///   /// ///  /// ///   /// /// ///\n";
	cout << "           ///////   ///  /// ///   /// ///  ///\n";

	
	
	int deposit(int, int);
	int withdraw(int, int);
	string Fname, Lname;
	int choice=0;
	int value1, value2, total;
	 

	do
	{
		cout << "\n\n";
		cout << "\t\t 1. Deposit\n";
		cout << "\t\t 2. Withdraw\n";
		cout << "\t\t 3. Exit\n\n";
		cout << "\t\t    What would you like to do?: \n";
		cin >> choice;


		if(choice == 1)
		{
			cout << "How much money would you like to deposit?\n";
			cin >> value1;
			total = deposit (value1, value2);
		}
        if(choice == 2)
	    {
		    cout << "How much money would you like to withdraw?\n";
			cin >> value2;
			total = withdraw(value1,value2);
        }	
		
		else if(choice == 3)
		{
			//User exits menu
		}
		else
		{
			cout << "Please enter a valid option\n";
		}
		if(choice >0 && choice <3)
		{
			cout << "You have $" << total << " left in your bank account...\n";
		}
	}while(choice != -1); 
      
	system("pause");
	return 0;
}
	int deposit(int num1, int num2)
		{
			return (500 + num1);
		}
	int withdraw(int num1, int num2)
		{
			return(500 - num2);
		}
You should listen to your compiler.

At line 35, you declare value2 without initialising it.

At line 52, you pass it into deposit while it's still uninitialised.

I don't understand why you're passing 2 arguments into deposit and withdraw. Each of those functions only uses one of the arguments that are passed into it.
Last edited on
so what should I do then, I don't get it...
2 things I would recommend:

1) Think about why you're passing 2 arguments into deposit and withdraw.

Does deposit need to take num2 as an argument? If so, what should it be doing with that argument?

Does withdraw need to take num1 as an argument? If so, what should it be doing with that argument?

Once you've figured that out, adjust the function definitions accordingly.

2) Always make sure your variables have values assigned to them before attempting to use the values in them. Otherwise, you'll wind up with random values in those variables.
I know maybe I sound desperate here but could you tell me how I should fix it? It is due tomorrow and I'm so screwed if I don't get this done by then. I know it's a better thing for me to do on my own but I'm already out of time, unfortunately...
All I need to make this program do is save the users balance when he/she withdraws or deposits. And able to create new users with passwords and usernames.
My point 2) will fix the error message you're getting.

What do you mean by "save"? Write it to a file?
yeah like to inFile and save the users on a txt file.
Does that mean value should be value1=0 as well as value2=0
If you think that's a sensible initial value for them then, yes, by all means.
Okay I changed my program around a bit. How does it look?

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
using namespace std;





int main()
{
		cout << "       ///    /// //////// ///     //////// //////// ///    /// ////////\n";
		cout << "      ///    /// ///      ///     ///      ///  /// ////////// ///\n";
  		cout << "     /// // /// ///////  ///     ///      ///  /// /// // /// ////////\n";
		cout << "    ////////// ///      ///     ///      ///  /// ///    /// ///\n"; 
		cout << "     /// ///  //////// /////// //////// //////// ///    /// ////////\n";
		cout << "                            //////// ////////\n";
		cout << "                              ///   ///  ///\n";
		cout << "                             ///   ///  ///\n";
		cout << "                            ///   ///  ///\n";
		cout << "                           ///   ////////\n";
		cout << "                       ////////\n";
		cout << "                      ///        ///      ///\n";
		cout << "                     ///      //////// ////////\n";
		cout << "                    ///        ///       ///\n";
		cout << "                   ////////\n";
		cout << "               ///////     ///    ///   /// ///  ///\n";
		cout << "              ///   /// ///  /// ///// /// /// ///\n";
		cout << "             ////////  //////// /// ///// /////\n";
		cout << "            ///   /// ///  /// ///   /// /// ///\n";
		cout << "           ///////   ///  /// ///   /// ///  ///\n";
		
		double balance, withdraw, deposit;
		balance = 0;
		int choice;
		string name;

		cout << "\n\t\t\t\t Menu";
		cout << "\n\n";
		cout << "\t\t\t*************************\n";
		cout << "\t\t\t* 1. Balance            *\n";
		cout << "\t\t\t* 2. Deposit            *\n";
		cout << "\t\t\t* 3. Withdraw           *\n";
		cout << "\t\t\t* 4. Exit               *\n";
		cout << "\t\t\t*************************\n\n";
		cout << "\t\t\tWhat is your name: ";
		cin >> name;
		cout << "\t\t\tWhat would you like to do " << name << "?: ";
		cin >> choice;
		cout << "\n";

		while (choice !=4)
		{
			switch(choice)
			{
			case 1 : cout << "The current balance in your account is " << balance << endl;
				break;
			case 2 : cout << "Enter the amount you would like to add to your account: ";
				cin >> deposit;
				balance = balance + deposit;
				cout << "You have entered in " << deposit << endl;
				break;
			case 3 : cout << "Enter an amount you would like to withdraw: ";
				cin >> withdraw;
				balance = balance - withdraw;
				cout << "You have withdrawn " << withdraw << "from your account.\n";
				break;
			default: cout << "You have entered a wrong input.\n";
			}
			cout << "\n What would you like to do next " << name << "?:";
			cin >> choice;
		}
		
}


the only thing is that it won't display the ouput where I ask for the user name...
Last edited on
Topic archived. No new replies allowed.