i have an assignment due for my c++ class where we have to input from the keyboard the quantity and input from the keyboard the stock price.

so that it outputs as:
Stock Item Quantity Unit Price Total Value
----------------------------------------------
Television 5 368.00 1840.00
Video Recorder 8 268.00 2144.00
Camera 9 300.00 2700.00
DVD 10 468.00 4680.00
Hi Fi Stereo 13 2500.00 32500.00
Video CD 25 345.00 8625.00
----------------------------------------------
Gross Total: 52489.00

this is the code i have so far. i know i need to declare everything but i don't know how or where i should put it if any one has any advice that would be helpful. i hope i've given all the information you need.

#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;

void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()

{
          
          int item [6] = { Television, VideoRecorder, Camera, DVD, HiFiStereo, VideoCD  };
          int total = 0;    
    
     cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     
     cout<<setw(15)<< "Item" //fomats the output
         <<setw(11)<< "Quantity"
         <<setw(13)<< "Unit Price"
         <<setw(14)<< "Total Value"<<endl;
     
cout<<"============================================================="<<endl;
     
     cout<<setw(15)<< "Television"
         <<setw(11)<< qty1
         <<setw(13)<< price1
         <<setw(14)<< totalStockValue1<<endl;
     cout<<setw(15)<< "Video Recorder"
         <<setw(11)<< qty2
         <<setw(13)<< price2
         <<setw(14)<< totalStockValue2<<endl;   
     cout<<setw(15)<< "Camera"
         <<setw(11)<< qty3
         <<setw(13)<< price3
         <<setw(14)<< totalStockValue3<<endl;
     cout<<setw(15)<< "DVD"
         <<setw(11)<< qty4
         <<setw(13)<< price4
         <<setw(14)<< totalStockValue4<<endl; 
     cout<<setw(15)<< "HiFi Stereo"
         <<setw(11)<< qty5
         <<setw(13)<< price5
         <<setw(14)<< totalStockValue5<<endl; 
     cout<<setw(15)<< "Video CD"
         <<setw(11)<< qty6
         <<setw(13)<< price6
         <<setw(14)<< totalStockValue6<<endl;

cout<<"============================================================="<<endl;

cout<<setw(45)<< "Gross Total: "
    <<setw(4)<<gross<<totalGrossValue<<endl;

 system("pause"); 
 
          for(int k = 0; k < 6; k++)
{

input(qtyStock[k], stockPrice[k], k);
gross += computation(qtyStock[k], stockPrice[k], stockValue[k]);

}
for (int i = 0; i<SIZE; i++)
{
    getNumber(item[i], i+1);
    sum(item[i],total);
}
    output (item, total, SIZE);
          system("pause");
}
void getNumber(int &num, int numCount)
{    
     cout<<"Enter Number" << numCount<< ":";
     cin>>num;
}
      heading();
                for(int m = 0; m < 6; m++)
{
                output(qtyStock[m], stockPrice[m], stockValue[m], m);
}
                outputGross(gross);
}

wow, what did you do?

Your problem seems to be here

for (int i = 0; i<SIZE; i++)
{
    getNumber(item[i], i+1);
    sum(item[i],total);
}
    output (item, total, SIZE);
          system("pause");
}
void getNumber(int &num, int numCount)
{    
     cout<<"Enter Number" << numCount<< ":";
     cin>>num;
}
      heading();
                for(int m = 0; m < 6; m++)
{
                output(qtyStock[m], stockPrice[m], stockValue[m], m);
}
                outputGross(gross);
}

Try and see the fault if you can't I will help you. It is much better if you can see it.

Try and slowly read what you are doing here.

the most i need help with is declaring Television, VideoRecorder, Camera, DVD, HiFiStereo, VideoCD. i think once i have those declared i can fix the rest.

You need a variable or array to get the Quantity and Sum

You need a variable or array to get the Quantity and Sum

does that mean i need to put
int quantity =0
int sum = 0

after int total =0?

You could do it like that, It might be easier for you to use more variables.

Quantity1
Sum1
Quantity2
Sum2

etc

oh i understand that thank you.

/*Alysha Jacobson
6351476*/

#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;

void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()

{
    int qty1;
    cout << "Please enter the quantity of Televisions: "<<endl;
    cin >> qty1;
    int qty2;
    cout << "Please enter the quantity of Video Recorder: "<<endl;
    cin >> qty2;
    int qty3;
    cout << "Please enter the quantity of Camera: "<<endl;
    cin >> qty3;
    int qty4;
    cout << "Please enter the quantity of DVD: "<<endl;
    cin >> qty4;
    int qty5;
    cout << "Please enter the quantity of HiFi Stereo: "<<endl; 
    cin >> qty5;
    int qty6;
    cout << "Please enter the quantity of Video CD: " <<endl;
    cin >> qty6; 
    
    int price1;
    cout << "Please enter the quantity of Televisions: "<<endl;
    cin >> price1;
    int price2;
    cout << "Please enter the quantity of Video Recorder: "<<endl;
    cin >> price2;
    int price3;
    cout << "Please enter the quantity of Camera: "<<endl;
    cin >> price3;
    int price4;
    cout << "Please enter the quantity of DVD: "<<endl;
    cin >> price4;
    int price5;
    cout << "Please enter the quantity of HiFi Stereo: "<<endl; 
    cin >> price5;
    int price6;
    cout << "Please enter the quantity of Video CD: " <<endl;
    cin >> price6;
     
     float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
     float totalStockValue2 = qty2 * price2;
     float totalStockValue3 = qty3 * price3;
     float totalStockValue4 = qty4 * price4;
     float totalStockValue5 = qty5 * price5;
     float totalStockValue6 = qty6 * price6;

     float totalGrossValue = totalStockValue1 + totalStockValue2 + totalStockValue3 + totalStockValue4 + totalStockValue5 + totalStockValue6; //calculates the total value of all the inputs
     
     
     cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     
     cout<<setw(15)<< "Item" //fomats the output
         <<setw(11)<< "Quantity"
         <<setw(13)<< "Unit Price"
         <<setw(14)<< "Total Value"<<endl;
     
cout<<"============================================================="<<endl;
     
     cout<<setw(15)<< "Television"
         <<setw(11)<< qty1
         <<setw(13)<< price1
         <<setw(14)<< totalStockValue1<<endl;
     cout<<setw(15)<< "Video Recorder"
         <<setw(11)<< qty2
         <<setw(13)<< price2
         <<setw(14)<< totalStockValue2<<endl;   
     cout<<setw(15)<< "Camera"
         <<setw(11)<< qty3
         <<setw(13)<< price3
         <<setw(14)<< totalStockValue3<<endl;
     cout<<setw(15)<< "DVD"
         <<setw(11)<< qty4
         <<setw(13)<< price4
         <<setw(14)<< totalStockValue4<<endl; 
     cout<<setw(15)<< "HiFi Stereo"
         <<setw(11)<< qty5
         <<setw(13)<< price5
         <<setw(14)<< totalStockValue5<<endl; 
     cout<<setw(15)<< "Video CD"
         <<setw(11)<< qty6
         <<setw(13)<< price6
         <<setw(14)<< totalStockValue6<<endl;

cout<<"============================================================="<<endl;

cout<<setw(45)<< "Gross Total: "
    <<setw(4)<<gross<<totalGrossValue<<endl;

 system("pause"); 
 
          for(int k = 0; k < 6; k++)
{

input(qtyStock[k], stockPrice[k], k);
gross += computation(qtyStock[k], stockPrice[k], stockValue[k]);

}
for (int i = 0; i<SIZE; i++)
{
    getNumber(item[i], i+1);
    sum(item[i],total);
}
    output (item, total, SIZE);
          system("pause");
}
void getNumber(int &num, int numCount)
{    
     cout<<"Enter Number" << numCount<< ":";
     cin>>num;
}
      heading();
                for(int m = 0; m < 6; m++)
{
                output(qtyStock[m], stockPrice[m], stockValue[m], m);
}
                outputGross(gross);
}

this is what i have now.

I am sorry, I don't have a compiler is it working or not?

If not where is the error. Or do you just want to review your code.

It looks excessive but It looks like it should work.

void getNumber(int &num, int numCount)
{    
        cout<<"Enter Number" << numCount<< ":";
        cin>>num;
[B]    }[/B]
    heading();
    for(int m = 0; m < 6; m++)
    {
        output(qtyStock[m], stockPrice[m], stockValue[m], m);
    }
    outputGross(gross);
}

What are you doing here?

I think you have an error here. an extra }

thank you for helping me so much. i have a bit of trouble. i know its excessive but i didnt know how to shorten it then make it work.

my compiler error list is:
'stockPrice' undeclared
'input' undeclared
'stockValue' undeclared
'computation' undeclared
'SIZE' undeclared
'item' undeclared
'getNumber' undeclared
'total' undeclared
'sum' undeclared
'output' undeclared
In function `void getNumber(int&, int)'
'void getNumber(int&, int)' used prior to declaration
'heading' undeclared
'qtyStock' undeclared
'stockPrice' undeclared
'stockValue' undeclared
'output' undeclared
'outputGross' undeclared

i changed what you said to this:

void getNumber(int &num, int numCount)
{    
     cout<<"Enter Number" << numCount<< ":";
     cin>>num;
     heading();
                for(int m = 0; m < 6; m++)
{
                output(qtyStock[m], stockPrice[m], stockValue[m], m);
}
                outputGross(gross);
}

i can't put into words how much i thank you for helping me.

for all the undeclared values. Just Declare them as Zero;

Like you did there

int total = 0;

For:

In function `void getNumber(int&, int)'
'void getNumber(int&, int)' used prior to declaration

I don't see the error, but Why do you have a loop when you are calling getNumber and then you are looping again in getNumber.

Try initializing everything to 0 and see if that fixes it.

ok so i got rid of the for loop realised it was useless.

#include<iostream.h> //is used so it will display output to the user and that input can be read from the keyboard
#include<iomanip.h> //is used so that the user can format input
using namespace std;

void getQuanity(int&,int);
void getStock(int, int&);
void gross(int[],int,int);
int main()

{
  
    int qty1;
    cout << "Please enter the quantity of Televisions: "<<endl;
    cin >> qty1;
    int qty2;
    cout << "Please enter the quantity of Video Recorder: "<<endl;
    cin >> qty2;
    int qty3;
    cout << "Please enter the quantity of Camera: "<<endl;
    cin >> qty3;
    int qty4;
    cout << "Please enter the quantity of DVD: "<<endl;
    cin >> qty4;
    int qty5;
    cout << "Please enter the quantity of HiFi Stereo: "<<endl; 
    cin >> qty5;
    int qty6;
    cout << "Please enter the quantity of Video CD: " <<endl;
    cin >> qty6; 
    
    int price1;
    cout << "Please enter the price of Televisions: "<<endl;
    cin >> price1;
    int price2;
    cout << "Please enter the price of Video Recorder: "<<endl;
    cin >> price2;
    int price3;
    cout << "Please enter the price of Camera: "<<endl;
    cin >> price3;
    int price4;
    cout << "Please enter the price of DVD: "<<endl;
    cin >> price4;
    int price5;
    cout << "Please enter the price of HiFi Stereo: "<<endl; 
    cin >> price5;
    int price6;
    cout << "Please enter the price of Video CD: " <<endl;
    cin >> price6;
     
     float totalStockValue1 = qty1 * price1; //the equation that calculates the price of the item multipled by the quantity
     float totalStockValue2 = qty2 * price2;
     float totalStockValue3 = qty3 * price3;
     float totalStockValue4 = qty4 * price4;
     float totalStockValue5 = qty5 * price5;
     float totalStockValue6 = qty6 * price6;

     float totalGrossValue = totalStockValue1 + totalStockValue2 + totalStockValue3 + totalStockValue4 + totalStockValue5 + totalStockValue6; //calculates the total value of all the inputs
     
     
     cout<<setiosflags(ios::fixed)<<setprecision(2); //sets the output to 2 decimal places
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     cout<<setiosflags(ios::fixed)<<setprecision(2);
     
     cout<<setw(15)<< "Item" //fomats the output
         <<setw(11)<< "Quantity"
         <<setw(13)<< "Unit Price"
         <<setw(14)<< "Total Value"<<endl;
     
cout<<"============================================================="<<endl;
     
     cout<<setw(15)<< "Television"
         <<setw(11)<< qty1
         <<setw(13)<< price1
         <<setw(14)<< totalStockValue1<<endl;
     cout<<setw(15)<< "Video Recorder"
         <<setw(11)<< qty2
         <<setw(13)<< price2
         <<setw(14)<< totalStockValue2<<endl;   
     cout<<setw(15)<< "Camera"
         <<setw(11)<< qty3
         <<setw(13)<< price3
         <<setw(14)<< totalStockValue3<<endl;
     cout<<setw(15)<< "DVD"
         <<setw(11)<< qty4
         <<setw(13)<< price4
         <<setw(14)<< totalStockValue4<<endl; 
     cout<<setw(15)<< "HiFi Stereo"
         <<setw(11)<< qty5
         <<setw(13)<< price5
         <<setw(14)<< totalStockValue5<<endl; 
     cout<<setw(15)<< "Video CD"
         <<setw(11)<< qty6
         <<setw(13)<< price6
         <<setw(14)<< totalStockValue6<<endl;

cout<<"============================================================="<<endl;

cout<<setw(45)<< "Gross Total: "
    <<setw(4)<<gross<<totalGrossValue<<endl;

 system("pause"); 

}

it works, thank you but if you could help me with one more thing. i know i can get rid of making that excessive code by making it qty1, qty2, etc enum but then i don't know how to make it come up with a question so they can answer it after. is there a way to clear all the cout's and cin's so it just shows the output?

you can use arrays.

and for or while loops.

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.