Result of variable's in my object

Ok before i show you the code i'll explain what i want to do with it. I just want to multiply the variable quantity with balance to display the result(variable balance) when i'll call the Getfunction . I don't know how to declare it in my object because i can't write the variable within the objet's, i can only write numbers when i declare int.


-----------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include "Account class.h"

using namespace std;



int main()
{

    CustomerAccount Item( 5, 1, amount,"marteau", "sa frappe" );
    CustomerAccount Item2( 23536478, 777, amount,"Bardeau" ,"C cher en sale");
    CustomerAccount Item3( 123, 3, amount, "Diaman", "nice deal" );

    cout << "Nom: " << Item.getAccountName() << "\nPrix de l'item en question: " << Item.getAccountBalance() << "\nnombre: "<<Item.getAccountQuantity()  << "\nLe montant total est : "<< Item.getAccountAmount() << "\nDescription: "<< Item.getAccountDescription() << endl;
    cout << "Nom: " << Item2.getAccountName() << "\nPrix de l'item en question: " << Item2.getAccountBalance() << "\nnombre: "<<Item2.getAccountQuantity() << "\nLe montant total est : "<< Item.getAccountAmount() << "\nDescription: "<< Item2.getAccountDescription() << endl;
    cout << "Nom: " << Item3.getAccountName() << "\nPrix de l'item en question: " << Item3.getAccountBalance() << "\nnombre: "<<Item3.getAccountQuantity() << "\nLe montant total est : "<< Item.getAccountAmount() << "\nDescription: "<< Item3.getAccountDescription() << endl;

}



-----------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include "Account class.h"
using namespace std;


CustomerAccount::CustomerAccount ( int pBalance, int pQuantity, int pAmount, string pName, string pDescription )
{

    balance=0;
    quantity=0;
    amount= 0;
    name="";
    description="";

    setAccountBalance( pBalance );
    setAccountQuantity( pQuantity);
    setAccountAmount( pAmount );
    setAccountName( pName );
    setAccountDescription( pDescription );
}

//
void CustomerAccount::setAccountBalance( int pBalance)
{
    balance=pBalance;
}

int CustomerAccount::getAccountBalance()
{
    return balance;
}

void CustomerAccount::setAccountQuantity( int pQuantity)
{
    quantity=pQuantity;
}

int CustomerAccount::getAccountQuantity()
{
   return quantity;
}

void CustomerAccount::setAccountAmount( int pAmount )
{
    amount=quantity*balance;
    amount=pAmount;
}

int CustomerAccount::getAccountAmount()
{
    return amount;
}


void CustomerAccount::setAccountName( string pName )
{
    name=pName;
}

string CustomerAccount::getAccountName()
{
    return name;
}

void CustomerAccount::setAccountDescription( string pDescription )
{
    description=pDescription;
}

string CustomerAccount::getAccountDescription()
{
    return description;
}



-----------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <string>

using namespace std;


class CustomerAccount
{

public:
      CustomerAccount( int, int, int, string, string );

      void setAccountBalance( int );
      int getAccountBalance();

      void setAccountQuantity( int );
      int getAccountQuantity();

      void setAccountAmount( int );
      int getAccountAmount();


      void setAccountName( string );
      string getAccountName();

      void setAccountDescription( string );
      string getAccountDescription();


private:
    int balance, quantity, amount;
    string name, description;
};
Last edited on
i hope i wrote my question clearly, english isn't my main language
Last edited on
I guess nobody knows the answer :)
Is it too hard for beginner forum?
closed account (D80DSL3A)
I examined your post yesterday but couldn't figure out what the issue is.
I didn't find any question being asked. Questions typically end with a question mark (?).
Your statements lead me to think that the problem has something to do with how the value of amount is found.
One function looks a bit odd:
1
2
3
4
5
void CustomerAccount::setAccountAmount( int pAmount )
{
    amount=quantity*balance;
    amount=pAmount;
}

This assigns amount a value twice. Is this where the issue lies? <- ( note the ? mark )
Well, i answered my question myself. Look at the constructor. I had to use display message to get a int number to display and put the Cout in there too.

If you want the code just ask me personaly.
closed account (D80DSL3A)
Well, i answered my question myself.

Excellent! Troubleshooting your own code is an important skill.
Topic archived. No new replies allowed.