Can someone tell me why my code is not writing to a data file! I get no errors and everything looks great!
#include "Account.h"
#include <iostream>
#include <fstream>
#include <cstdlib> // for exit function
using std::ofstream;
int main() {
ofstream outdata;
const int SIZE = 6;
//Account array
Account Account_array[SIZE] = { Account(832442, 560.10, .02),
Account(832443, 1020.58, .04),
Account(832444, 78.00, .02),
Account(832447, 1200.12, .04),
Account(832449, 489.33, .02),
Account(833001, 105.74, .02)};
// Loop to display Account details
for (int x=0; x<6; x++) {
Account_array[x].account_details();
}
outdata.open("AccountDetails.dat"); // Opens the file
if ( !outdata ) { //File could not be opened
cout << "Error: file could not be opened" << endl;
exit(1);
for (int x=0; x<6; x++) {
Account_array[x].account_details();
outdata.close();
}
}
return 0;
}
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
//Account class
class Account {
private:
int number;
double balance;
double rate;
public:
Account(); // Constructor
Account (int, double, double);
void setNumber(int);
void setBalance(double);
void setRate(double);
int getNumber();
double getBalance();
double getRate();
void account_details();
string string_account_details();
};
Account::Account()
{
number =0;
balance = 0;
rate = 0;
}
Account::Account(int number, double balance, double rate) {
Account::number = number;
Account::balance = balance;
Account::rate= rate;
}
void Account::setNumber(int number) {
Account::number = number;
}
void Account::setBalance(double balance) {
Account::balance = balance;
}
void Account::setRate(double rate) {
Account::rate = rate;
}
int Account::getNumber() {
return number;
}
double Account::getBalance() {
return balance;
}
double Account::getRate() {
return rate;
}
void Account::account_details() {
cout << "The current account number is " << number <<
" with a balance of $" << balance << " and an interest rate of " << rate << ".\n\n";
}