sfuo 111 Practically a Master Poster

Since I know nothing about bitfields I don't know what value to assign it but you can give it a value by going

#include <iostream>
#include <conio.h>

#define K 3

using namespace std;

int main()
{
	struct test
	{
		char testa:6;
		char textb:10;
	}testvar[2][K];
	//I put in 111 as the value but it just gives me some ascii character
	testvar[0][K].testa = 111;
	cout << testvar[0][K].testa << endl;
	
	getch();
	
	return 0;
}
sfuo 111 Practically a Master Poster

Yeah, add it to the one with the ifsteam and ofstream in it.

Delete one of the sets of class declarations out of the main() or it will say it is already defined.

sfuo 111 Practically a Master Poster

Yeah put it in there and then right below your getBalance() function add getTotalLostToFee() and getTransactionCounter().

sfuo 111 Practically a Master Poster

I'm not sure what compiler you are using but it should be telling you that you cannot have 2 main() functions declared in the same project.

Also by the looks of it, unless you just cut it off, you did not close the #ifndef "COSC214Lab3.h"
statement with
#endif at the bottom of the file

sfuo 111 Practically a Master Poster

Also you want the transactionCounter++; on deposits too.

That is if they are counted as transactions but I'm pretty sure they are.

And I see you still have single quotes around savings in the input.txt reader

sfuo 111 Practically a Master Poster

I never even asked you about the WITHDRAW_FEE variable but is that supposed to be a percent or just a flat rate?

The way I set it up it is a percentage of what you withdraw so 0.50 would be 50% which is huge. If you want it as a flat $0.50 fee change it to

balance -= amount + WITHDRAW_FEE;
sfuo 111 Practically a Master Poster

Yeah I actually rewrote the whole thing out.

Just post your class structure and I'll take a look at what you have unless it is no different from your last code post.

"Account.h"
"Account.cpp"

sfuo 111 Practically a Master Poster

I understand what you mean but would you want it for a multiple use counter or just how much you lost from the transaction fee on the one run of the program?

For these you could just declare a variable in the class structures and then whenever you withdraw it goes

balance -= amount*(1+WITHDRAW_FEE);
//name the variables whatever you want
totalLostToFee += amount*WITHDRAW_FEE;
transactionCounter++;

This code would go into your withdraw() functions and then you would make getTotalLostToFee() and getTransactionCounter() returning themselves. Use it the same way you output the balances to the text file.

sfuo 111 Practically a Master Poster

Why are you using a multidimensional array?

If you explain a bit more stuff I might be able to help.

sfuo 111 Practically a Master Poster

Just noticed that when I copy pasted I left some stuff in the main as savingsAccount when it should be checkingAccount.

while(inData >> accountType >> transactionType >> amount )
	{
		if( accountType == "savings" )
		{
			
			if( transactionType == "deposit" )
			{
				savingsAccount.deposit(amount);
				
			}
			else if( transactionType == "withdraw" )
			{
				savingsAccount.withdraw(amount);
			}
		}
		else if( accountType == "checking" )
		{
			if( transactionType == "deposit" )
			{
				savingsAcco2unt.deposit(amount);
			}
			else if( transactionType == "withdraw" )
			{
				savingsAccount.withdraw(amount);
			}
		}
	}

should change to

while(inData >> accountType >> transactionType >> amount )
	{
		if( accountType == "savings" )
		{
			
			if( transactionType == "deposit" )
			{
				savingsAccount.deposit(amount);
				
			}
			else if( transactionType == "withdraw" )
			{
				savingsAccount.withdraw(amount);
			}
		}
		else if( accountType == "checking" )
		{
			if( transactionType == "deposit" )
			{
				//change here
				checkingAccount.deposit(amount);
			}
			else if( transactionType == "withdraw" )
			{
				//change here
				checkingAccount.withdraw(amount);
			}
		}
	}
sfuo 111 Practically a Master Poster

OK the format might be a bit different but it works.

This writes to "output.txt" and reads in from "input.txt"

"account.h"

#ifndef ACCOUNT_H
#define ACCOUNT_H

//SAVINGS ACCOUNT
class SavingsAccount
{
	double balance;
	static const double WITHDRAW_FEE = 0.0;
	
	public:
		
	SavingsAccount();
	SavingsAccount( double balance );
	
	void setBalance( double amount );
	
	void withdraw( double amount );
	void deposit( double amount );
	
	double getBalance();
};

//CHECKING ACCOUNT
class CheckingAccount
{
	double balance;
	static const double WITHDRAW_FEE = 0.5;
	
	public:
		
	CheckingAccount();
	CheckingAccount( double balance );
	
	void setBalance( double amount );
	
	void withdraw( double amount );
	void deposit( double amount );
	
	double getBalance();
};

//SAVINGS ACCOUNT FUNCTIONS
SavingsAccount::SavingsAccount()
{
	balance = 100.0;
}

SavingsAccount::SavingsAccount( double balance )
{
	balance = balance;
}

void SavingsAccount::setBalance( double amount )
{
	balance = amount;
}

void SavingsAccount::withdraw( double amount )
{
	balance -= amount*(1+WITHDRAW_FEE);
}

void SavingsAccount::deposit( double amount )
{
	balance += amount;
}

double SavingsAccount::getBalance()
{
	return balance;
}

//CHECKING ACCOUNT FUNCTIONS

CheckingAccount::CheckingAccount()
{
	balance = 100.0;
}

CheckingAccount::CheckingAccount( double balance )
{
	balance = balance;
}

void CheckingAccount::setBalance( double amount )
{
	balance = amount;
}

void CheckingAccount::withdraw( double amount )
{
	balance -= amount*(1+WITHDRAW_FEE);
}

void CheckingAccount::deposit( double amount )
{
	balance += amount;
}

double CheckingAccount::getBalance()
{
	return balance;
}

#endif

"main.cpp"

#include <fstream>
#include "account.h"

using namespace std;

int main()
{
	SavingsAccount savingsAccount;
	CheckingAccount checkingAccount;
	
	ifstream inData("input.txt");
	ofstream outData("output.txt");
	
	string transactionType, accountType;
	double amount;
	
	/* delete if you want
	format for "input.txt"
	
	accountType transactionType amount
	
	*/
	while(inData >> …
sfuo 111 Practically a Master Poster

Give me about 5 min I'm writing out the whole thing to see what is going on and I will post a working copy in a bit.

sfuo 111 Practically a Master Poster

First off why do you have 2 main() functions declared?

I'm guessing one of your errors is from that.

Also you have 2 constructors in each class but you are only declaring 1.

SavingsAccount::SavingsAccount()
{
	balance = 100.0;
}

SavingsAccount::SavingsAccount( double balance )
{
	balance = balance;
}

is what you want I am assuming

sfuo 111 Practically a Master Poster

Are you sure?

In my quick test code I have a static const double working.

Post your class declarations.

sfuo 111 Practically a Master Poster

Change your "WITHDRAW_FEE" declarations to

static const double WITHDRAW_FEE = 0.0;

Change the value to what you want but in order to declare a constant variable inside a class you need to make it static.

Also, you cannot assign a return type to a constructor.

You have:

void SavingsAccount::SavingsAccount()

and you want to change that to

//remove void
SavingsAccount::SavingsAccount()
sfuo 111 Practically a Master Poster

I'm not 100% sure what you are asking is this correct?

#include <iostream>
#include <string>

using namespace std;

int main()
{

	string arrcon[2];
	
	arrcon[0] = "John";
	arrcon[1] = "56";
	
	for( int i = 0; i < 2; i++ )
	{
		cout << arrcon[i] << endl;
	}
	
	system("PAUSE");
	return 0;
}
sfuo 111 Practically a Master Poster

First off, I think you are missing a semicolon at the end of your SavingsAccount class (line 14, Account.cpp).

For your withdraw and deposit functions you could use:

///savings class


void SavingsAccount::withdraw(double amount)
{
	balance -= amount*(1+WITHDRAW_FEE);
}

void SavingsAccount::deposit(double amount)
{
	balance += amount;	
}


//checking class


void CheckingAccount::withdraw(double amount)
{
	balance -= amount*(1+WITHDRAW_FEE);	
}

void CheckingAccount::deposit(double amount)
{
	balance += amount;	
}

double CheckingAccount::getBalance()
{
	return balance;	
}
sfuo 111 Practically a Master Poster

Here is what I came up with.

"mystuff.h"

#ifndef MYSTUFF_H
#define MYSTUFF_H

void randomize();

int random( int high, int low = 0);

int getMax( int A[] );

int getMin( int A[] );

int swap( int A[] );

#endif

"mystuff.cpp"

#include <time.h>
#include <stdlib.h>

#include "mystuff.h"

void randomize()
{
	srand(time(NULL));
}

int random( int high, int low )
{
	return rand() % (high-low) + low;
}

int getMax( int A[] )
{
	int max = A[0];
	for( int i = 1; i < 10; i++ )
	{
		if( A[i] > max )
		{
			max = A[i];
		}
	}
	return max;	
}

int getMin( int A[] )
{
	int min = A[0];
	for( int i = 1; i < 10; i++ )
	{
		if( A[i] < min )
		{
			min = A[i];
		}
	}
	return min;	
}

int swap( int A[] )
{
	for( int i = 0; i < 10; i++ )
	{
		int temp = A[i];
		int ran = random(10);
		A[i] = A[ran];
		A[ran] = temp;		
	}
	return A[10];
}

"array.cpp"

#include <iostream>

#include "mystuff.h"

using namespace std;

int main()
{
	//declare variables and set random seed
	int A[10], min, max;
	randomize();
	
	//make random numbers and assign to array
	for(int i = 0; i < 10; i++)
	{
		A[i] = random(100, -100);
	}
	
	//find min and max numbers in array
	min = getMin( A );
	max = getMax( A );
	
	//output array before shuffled
	
	for( int i = 0; i < 10; i++ )
	{
		if( …
tux4life commented: Since when do we provide free cookies? -4
sfuo 111 Practically a Master Poster

Yes, my routers are set up so the 1st one is 192.168.1.1 and it is in DMZ mode so all traffic goes to the second wireless router and that is 192.168.5.1. Then our server and all computers are plugged into the 5.1 router and the computers obtain their assigned ip addresses from the server. You could be right that nothing works because of the setup but do you think that if I moved this "server" program to the server that outsiders could connect to it?

sfuo 111 Practically a Master Poster

yeah I've already tried on the same computer and connecting to 127.0.0.1 or connecting to my brothers computer on my LAN 192.168.5.123. One of the main problems I think I have is that all the computers on my LAN get the same IP address from whatismyip.com and this has only started happening since we installed a 2nd router and a server at my house. Outsiders are able to connect to the actual server that we set up. Another problem might be the fact that this server is our DHCP. =(

sfuo 111 Practically a Master Poster

I tried it when he was at his house and I was at mine. He went to what is my ip.com to get his address for me to try to connect. He also opened up the port on his end.

sfuo 111 Practically a Master Poster

Hi I have been trying for a while to make a win32 app client be able to talk to a server app that I put on my friends computer. I am not 100% sure if the problem is caused by the fact that I have two routers which may interfere with my IP address. The following code works on my LAN and with the loop back address 127.0.0.1.

I am gonna put up the parts that have to do with winsock since it is using SDL/C++/winsock

For the client

bool ConnectToHost( int PortNo, char* IPAddress )
{
	WSADATA wsadata;
	int error = WSAStartup( 0x0202, &wsadata );
	
	if( error )
	{
		return false;
	}
	
	if( wsadata.wVersion != 0x0202 )
	{
		WSACleanup();
		return false;
	}
	SOCKADDR_IN target;
	
	target.sin_family = AF_INET;
	target.sin_port = htons( PortNo );
	target.sin_addr.s_addr = inet_addr( IPAddress );
	
	//s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
	s = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
	
	if( s == INVALID_SOCKET )
	{
		return false;
	}
	
	if( connect( s, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR )
	{
		return false;
	}
	
	WSAAsyncSelect (s, hwnd, 1045, FD_READ | FD_CONNECT | FD_CLOSE);
	return true;
}

and for the server

bool ListenOnPort( int PortNo )
{
	WSADATA w;
	
	int error = WSAStartup ( 0x0202, &w );
	
	if( error )
	{
		return false;
	}
	
	if( w.wVersion != 0x0202 )
	{
		WSACleanup();
		return false;
	}
	
	SOCKADDR_IN addr;
	
	addr.sin_family = AF_INET;
	addr.sin_port = htons( PortNo );
	addr.sin_addr.s_addr = htonl( INADDR_ANY );
	
	//s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
	s …