I have this homework in which I have been working on it: but I dont know what im doing wrong :(

Could anyone help me:

#include <iostream>
#include <cstring>

using namespace std;

class Account
{	private:
		char number[8];
		char type;
		char owner[31];
		double balance;
		double interestRate;

	public:
	Account()
	{
		number[0] = '\0';
		type = 'S';
		owner[0] = '\0';
		balance = 0;
		interestRate = 0.05;
	}//default numbers
	char  getnumber();
		
	char gettype();
		
	char  getowner();
		
	double getbalance();
		
	double getinterestRate();
		
//get functions are usless with the print function
	void setnumber(char[]);
	void settype(char);
	void setowner(char[]);
	void setbalance(double);
	void setinterestRate(double);
	void interestpermonth();
	void print();
};


void Account::settype(char t)
{
	(t=='S' || t=='C' || t=='L')?type = t: 'S';
		
}//assign type if it is C, S or L

void Account::setowner(char o[])
{	int len;
	len = strlen (o); //length of the owner name
	if (len < 31)
		{strncpy(owner,o,len);//copy the owner name
		 owner[len]='\0';}
}

void Account::setbalance(double b)
{	if (b>= 0)
		balance=b;
}//set balance to the user description if it is positive 

void Account::setinterestRate(double ir)
{	if(ir >=0 && ir<=1)
		interestRate=ir;
}//set interest rate between 0 and 1

void Account::interestpermonth()
{
	balance= balance + (interestRate*balance/12);
}//formula to calculate the interest and add it to the balance

void Account::print()//function to print all the acount informations
{
	cout<<"number: "<<number<<endl;
	cout<<"type: "<<type<<endl;
	cout<<"owner: "<<owner<<endl;
	cout<<"balance before interest: "<<balance<<endl;
	interestpermonth();
	cout<<"balance after interest: "<<balance<<endl;
	cout<<"interestRate: "<<interestRate<<endl;
}

int main()
{
	Account a[3];//array that contains the 3 acounts
	a[0].setnumber("SAAA989");//seting the acount informations
	a[0].settype('L');
	a[0].setowner("elie malkkoun");
	a[0].setbalance(9987);
	a[0].setinterestRate(0.07);
	a[0].print();
	



}

The error that i get is:

In function 'int main()':
Line 87: warning: deprecated conversion from string constant to 'char*''
Line 89: warning: deprecated conversion from string constant to 'char*''

Not unless you tell us something about the errors you are getting. Otherwise, all we can do is make wild guesses.

The only thing that I see right off hand is that main() doesn't have a return statement, it's bad practice, but that's not a huge deal.

EDIT:
Just found this:

if(t=='S' || t=='C' || t=='L')?type = t: 'S';

You have attempted to combine an if with the "ternary" operator. The ternary operator is a "messy" shortcut for an if statement. You can't combine them like this. You need to use one or the other. You can use either here, but for this particular case a formal if is probably the better choice for readability and syntactical reasons:

if(t=='S' || t=='C' || t=='L')
  type = t;
else
  type = 'S';

yeah i updated my original post

OK, I see it now...

Those are just warnings. They mean that your compiler doesn't like that your class isn't const correct. You will have to fix that.

There should be other errors as well. What are the other errors?

I've also noticed that you don't have an implementation for Account::setnumber();

thanks guys i managed to make it work and i added set number thank you sorry for the trouble

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.