I am currently doing classes, but I am unable to print out my cout statements in the "elmo.modifyALL" function. I can get the other stuff to print correctly so far. This is my first time doing this kind of program, so I do not understand why I can't get cout statements in the "elmo.modifyALL" function to print out. Thanks


.h file:

class toyType
{
public:
       
       void print() const;
       void modifyALL(string m, double c, int stoc); 
       toyType(string m, double c, int stoc);
       toyType();
       
       
private:
             
       string toyname;
       double cost;
       int stockcount;
               
};

 void toyType::print()const
 {
      cout<<"Toyname"<<"   Cost   "<<"Stock Count"<<endl;
      cout<<toyname<<" $     "<<cost<<"    "<<stockcount<<endl;
 }
 
 
   toyType::toyType(string m, double c, int stoc)
{
     
     toyname = m;
     cost = c;
     stockcount = stoc;            
                 
}

  toyType::toyType()
{
  
  
  toyname = "Unknown";
  cost = 0;
  stockcount = 0;
                   
}
 
 
 
void elmo::modifyALL() 
{
  cout<<"Enter new information below..."<<endl;
  
  cout<<"Enter Toy name: "<<endl;
  cin>>toyname;
  cout<<"Enter Cost of toy: "<<endl;
  cin>>cost;
  cout<<"Enter number in stock: "<<endl;
  cin>>stockcount;   
    
}

.cpp file:

#include <iostream>
#include <iomanip>
using namespace std;
#include "Unknown.h"

int main()
{
    
    toyType ps3("Playstation 3",500,2000);
    toyType elmo;
    
    ps3.print();
    elmo.print();
    
    elmo.modifyAll(); 
  //  ps3.sale(2);
    
    elmo.print();
    ps3.print();
    
    system ("PAUSE");
    return 0;
}

Secondly in your header file u mistyped i hope :D :D :D :

void elmo::modifyALL()
{
cout<<"Enter new information below..."<<endl;

cout<<"Enter Toy name: "<<endl;
cin>>toyname;
cout<<"Enter Cost of toy: "<<endl;
cin>>cost;
cout<<"Enter number in stock: "<<endl;
cin>>stockcount;

}

which should be:

void toyType::modifyALL()
{
cout<<"Enter new information below..."<<endl;

cout<<"Enter Toy name: "<<endl;
cin>>toyname;
cout<<"Enter Cost of toy: "<<endl;
cin>>cost;
cout<<"Enter number in stock: "<<endl;
cin>>stockcount;

}

And finally :D
u declared the modifyALL method within the class body having 3.... arguments

void modifyALL(string m, double c, int stoc);

while later u define it taking no arguments...

void elmo::modifyALL()
{
cout<<"Enter new information below..."<<endl;

cout<<"Enter Toy name: "<<endl;
cin>>toyname;
cout<<"Enter Cost of toy: "<<endl;
cin>>cost;
cout<<"Enter number in stock: "<<endl;
cin>>stockcount;

}

In addition in main u misstyped the

elmo.modifyAll();
shoul be:
elmo.modifyALL();

So put it all together:

...
#include <string>
....
class ToyType()
{
...
void modifyALL();
};

void toyType::modifyALL()
{
....

}


.....



int main()
{
...
//U have misstyped:
//elmo.modifyAll();

//CORRECT IS:
elmo.modifyALL();
....
}

Thank you for your reply. I need help with one more thing. I have a stock count of 2000 Playstation 3s. Let's say that someone buys 2 Playstations 3s...I want my stock count to go down to 1998. How would I do that? I tried something which works, but I know it isn't the correct way of doing it.. This is an example of what I did. What is the right way of doing it though? Below is my .cpp and .h file

Cplusplus]
void toyType::sale(int s)
{
                      
   if ( stockcount >= 2000)
      stockcount = 1998;
   
}

.h file

class toyType
{
public:
       
       void print() const;
       void modifyALL();
       toyType(string m, double c, int stoc);
       toyType();
       void sale(int s);
       
       
private:
             
       string toyname;
       double cost;
       int stockcount;
               
};

 void toyType::print()const
 {
      cout<<"Toyname"<<" Cost "<<"Stock"<<endl;
      cout<<toyname<<" $"<<cost<<"  "<<stockcount<<endl;
 }
 
 
   toyType::toyType(string m, double c, int stoc)
{
     
     toyname = m;
     cost = c;
     stockcount = stoc;            
                 
}

  toyType::toyType()
{
  
  
  toyname = "Unknown";
  cost = 0;
  stockcount = 0;
                   
}
 
 
 
  void toyType::modifyALL()
{
  cout<<"Enter new information below..."<<endl;
  
  cout<<"Enter Toy name: "<<endl;
  cin>>toyname;
  cout<<"Enter Cost of toy: "<<endl;
  cin>>cost;
  cout<<"Enter number in stock: "<<endl;
  cin>>stockcount;      
    
}

void toyType::sale(int s)
{
                      
   if ( stockcount >= 2000)
      stockcount = 1998;
   
}

.cpp file

#include <iostream>
#include <iomanip>
using namespace std;
#include "Unknown.h"

int main()
{
    
    toyType ps3("Playstation3",500,2000);
    toyType elmo;
    
    ps3.print();
    elmo.print();
    
    elmo.modifyALL();
    ps3.sale(2);
    
    elmo.print();
    ps3.print();
    
    system ("PAUSE");
    return 0;
}

u can do simply like this:

void toyType::sale(int s)
{
		stockcount -=s;
}

The statement:

stockcount -=s;

is equivalent to:

stockcount =stockcount - s;

but the first is considered better code practice.

Now concerning your previous line:

if ( stockcount >= 2000)

if the 2000 stocks is not some special number concerning the task then i guess u dont need it, and thats why I removed it. :D

This question has already been answered. Start a new discussion instead.