Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:26:25+00:00 2026-06-05T17:26:25+00:00

I am making a program with which to save banking information (i.e., account, password,

  • 0

I am making a program with which to save banking information (i.e., account, password, balance). I am having trouble with a certain error but I’m not sure of the cause.

Here is the entire code.

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

int x = 0;

void addUser();
void login();
void deposit();
void withdrawl();

struct bankUser
{
    double balance;
    string account, password;
};

bankUser user[20];

int menu()
{
    ofstream myfile("bankmachine.txt", ios::app);
    char choice;

    cout << "1) Add account" << endl;
    cout << "2) Log in" << endl;
    cout << "3) Make deposit" << endl;
    cout << "4) Make withdrawl" << endl;
    cout << "5) Quit" << endl << endl;
    cout << "What would you like to do?: ";
    cin >> choice;
    cout << endl;

    switch (choice)
    {
        case '1':
            addUser();
            break;
        case '2':
            login();
            break;
        case '3':
            deposit();
            break;
        case '4':
            withdrawl();
            break;
        case '5':
            myfile << user[x].balance << endl;
            myfile.close();

            cout << "Thank you for using the banking system." << endl << endl;
            system ("pause");
            return 0;
            break;
        default:
            cout << "That is not a valid option. Please choose again." << endl << endl;
            menu();
    }
}

void addUser()
{
    if ((x >= 0) && (x < 20))
    {
        cout << "Please enter your desired account name: ";
        cin >> user[x].account; // Account name.
        cout << "Thank you, now please enter your desired password: ";
        cin >> user[x].password; // Account password.
        cout << "\nAccount created. You may now log in." << endl << endl;

        ofstream myfile("bankmachine.txt", ios::app); // Opens the text file at the end of the file (if data is already present).
        myfile << user[x].account << endl; // Writes to text file.
        myfile << user[x].password << endl; //  ^
        myfile.close(); // Close text file (important).

        x++; // Increases to simulate the addition of another user.
        menu();
    }

    else // Will display if user has entered 20 users.
    {
        cout << "You have entered the maximum number of users." << endl;
        menu();
    }
}

void deposit()
{
    int deposit;
    string answer;

    do
    {
        cout << "Please enter the amount of money that you would like to deposit: ";
        cin >> deposit;

        user[x].balance += deposit;

        cout << "Thank you. Your new balance is " << user[x].balance << "." << endl << endl;
        cout << "Would you like to make another deposit? (Y/N): ";
        cin >> answer;
    } while ((answer != "N") && (answer == "Y"));
    cout << endl;
    menu();
}

void withdrawl()
{
    int withdraw;
    string answer;

    do
    {
        cout << "Please enter the amount of money that you would like to withdraw: ";
        cin >> withdraw;

        if (withdraw <= user[x].balance)
        {
            user[x].balance -= withdraw;
        }

        else
        {
            cout << "\nSorry, you do not have sufficient funds to complete this withdrawl.\nPlease try again." << endl << endl;
            withdrawl();
        }

        cout << "Thank you. Your new balance is " << user[x].balance << "." << endl << endl;
        cout << "Would you like to make another withdrawl? (Y/N): ";
        cin >> answer;
    } while (answer != "N" && answer == "Y");
    cout << endl;
    menu();
}

void login() // Function to log in.
{
    string user, pw, usernameCheck, passwordCheck;
    double balance;

    cout << "Please enter your login information." << endl << endl;
    cout << "Account name: ";
    cin >> user;
    cout << "Password: ";
    cin >> pw;
    cout << endl;

    ifstream myfile("bankmachine.txt", ios::app);

    while (!myfile.eof()) // Loops until end of file.
    {
        getline(myfile, usernameCheck);
        if (usernameCheck == user)
        {
            getline(myfile, passwordCheck);
            if (passwordCheck == pw)
            {
                myfile >> balance;
                cout << "Login successful." << endl;
                cout << "Your balance is " << balance << "." << endl << endl;

                user[x].balance = balance;
            }

            else // If not, display:
            {
                cout << "Password incorrect." << endl << endl;
            }
        }
    }

    myfile.close(); // Close text file (important).
    menu();
}

int main()
{
    cout << "Welcome to the banking system." << endl << endl;
    menu();
}

I keep getting this error (on line 172):

request for member 'balance' in 'user.std::basic_string<_CharT, _Traits,
_Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>](((unsigned int)x))', which is of non-class type 'char'|

What is this caused by? How can I fix it? Any answers are appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:26:26+00:00Added an answer on June 5, 2026 at 5:26 pm

    Judging by the error provided it seems as if user is not of type struct bankUser, but a std::string.

    You are trying to assign a std::string (balance) to character at offset x of your std::string named user, which is doomed to fail.

    TL;DR user is not declared to be a struct bankUser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal I am making a program which generates a 3D maze and am having
I'm making a program which the user build directories (not in windows, in my
I am making a program which implements the mergesort algorithm but instead of dividing
So I'm making a program which is supposed to print a horizontal histogram of
I'm making a program which create a RAW socket in order to read all
I am making a timetabling program which does one to one matches from SubjectTeacherPeriod
I'm making a program that communicate with certain patient monitor using C sockets. I'm
I am thinking of making a little program in which two users would have
I need to save bookmarks for a program I am making. The bookmarks are
I'm making a program which opens a configured application after with the passed paramters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.