Create a check digit that is the remainder of the account number when it is divided by 5. This digit should be added to the end
of the 4 digit account number.
Account #12344

#include <cstdlib> // Standard C library...
#include <iostream> // Contains cout, cin objects...

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

    int accountNumber1, accountNumber2;
    double accountBalance1, accountBalance2, checkDigit;

    cout << "First account: Enter account number: ";
    cin >> accountNumber1;

    checkDigit = 4 //(accountNumber1 / 5) % 2;
    accountNumber1 = accountNumber1 + checkDigit;

    cout << "Enter balance: ";
    cin >> accountBalance1;

    cout << "Second account: Enter account number: ";
    cin >> accountNumber2;

    cout << "Enter balance: ";
    cin >> accountBalance2;

    cout << "Account#: " << accountNumber1 << " has a starting balance of: $" << accountBalance1;
    cout << "\nAccount#: " << accountNumber2 << " has a starting balance of: $" << accountBalance2;

    return 0;

}

accountnumber 1 is 1234
account number two is 5678

using the check digit the account1 should be 12344
and account2 should be 56783

checkDigit = accountNumber1 % 5;

what then is checkdigit

accountNumber1 / 5; ???

This is how to calculate the checkdigit.

checkDigit = accountNumber1 % 5;

The % operator is the modulus operator. You use it to get the remainder when dividing two numbers.accountNumber1 % 5 gives you the remainder when dividing accountNumber1 by 5.

Thank you, you are correct...

 * bankAccount
 * Instructions:
 * Create a BankAccount Structure that contains two fields, one for an integer
 *called accountNumber and one for a double called accountBalance. Create a main
 *program that prompts the user for a 4 digit account number and a beginning
 *balance for two accounts. Create a check digit that is the remainder of the
 *account number when it is divided by 5. This digit should be added to the end
 *of the 4 digit account number. Store the account number and the beginning
 *balance in each BankAccount Object...
 * 
 * Sample Output:
 * First account: Enter account number >>  1234
 * Enter balance >>  5
 * Second account: Enter account number >>  5678
 * Enter balance >>  3
 * 
 * Account #12344 had a starting balance of $5
 * Account #56783 had a starting balance of $3
 *
 * Created on October 28, 2013, 11:44 PM
 */

#include <cstdlib> // Standard C library...
#include <iostream> // Contains cout, cin objects...
#include <string>

#include "BankAccount.h" // Contains the C++ construct 'string'(class)...

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {

    BankAccount accountNumber1, accountNumber2;
    BankAccount accountBalance1, accountBalance2;

    int checkDigit;

    cout << "First account: Enter account number: ";
    cin >> accountNumber1.accountNumber;
    checkDigit = accountNumber1.accountNumber % 5;
    accountNumber1.accountNumber = accountNumber1.accountNumber * 10 + checkDigit;

    cout << "Enter balance: ";
    cin >> accountBalance1.accountBalance;

    cout << "Second account: Enter account number: ";
    cin >> accountNumber2.accountNumber;
    checkDigit = accountNumber2.accountNumber % 5;
    accountNumber2.accountNumber = accountNumber2.accountNumber * 10 + checkDigit;

    cout << "Enter balance: ";
    cin >> accountBalance2.accountBalance;

    cout << "Account#: " << accountNumber1.accountNumber << " has a starting balance of: $" << accountBalance1.accountBalance;
    cout << "\nAccount#: " << accountNumber2.accountNumber << " has a starting balance of: $" << accountBalance2.accountBalance;

    return 0;

}
 *
 * Created on October 29, 2013, 7:52 PM
 */

#ifndef BANKACCOUNT_H
#define BANKACCOUNT_H

struct BankAccount {
    int accountNumber;
    double accountBalance;
};

#ifdef  __cplusplus
extern "C" {
#endif

#ifdef  __cplusplus
}
#endif

#endif  /* BANKACCOUNT_H */
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.