cant get the value in double pointer
Sep 28, 2013 at 5:01pm UTC
Hi all,
I am having problem displaying the amount in the weekly sales. While i am able to get salesperson and noOfweek to display what i have set, the code is not able to show the correct value of amount which i have set it to be 50.
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
#include <iostream>
using namespace std;
class WeeklySales
{
char * salesPerson;
double *amount; // Pointer to an array
int noOfWeek; // Size of the array
public :
WeeklySales(char * sp, double a, int week)
{
salesPerson = sp;
amount = &a;
noOfWeek = week;
}
void show()
{
cout << salesPerson << "\n" << amount << "\n" << noOfWeek;
}
};
int main(int argc, char *argv[])
{
WeeklySales ob("Adam" , 50, 4);
ob.show();
return 0;
}
Sep 28, 2013 at 5:16pm UTC
On line 21 is *amount instead of amount
Sep 28, 2013 at 5:23pm UTC
damn. didnt saw that. after making it into *amount and changing line 15 to new double (a); i finally got it to work.
thanks loads
Topic archived. No new replies allowed.