I don't know to make the output

I'm just doing whatever I know but.... I don't know how to make it appear like the output the question need

So, this is the question

Write a program to create a customer’s bill for a company. The company sells five computer gadgets which are CD, keyboard, printer, pen drive and speaker. The unit prices are RM60.00 per pack, RM130.00, RM850.00, RM65.00 and RM72.50 respectively. The program must require user to input quantity of each piece of equipment purchased. It then calculates the cost of each item, the sub total, and the total cost after 3% sales tax. List of formula as stated below:

Total price = quantity * unit price (Note: for each item)
Sub total = total price of all item
Tax = 3% of sub total
Total = sub total + tax

The input data consist of a set integer representing the quantities of each item sold.


Example pf the input is shown below:
amount of CDs (per pack): 5
amount of keyboards : 120
amount of printers : 35
amount of pen drives : 236
amount of speakers : 83


The format for the output is as below:
1
2
3
4
5
6
7
8
9
10
11
QTY          DETAILS         UNIT PRICE                   TOTAL PRICE
______     ________          ____________                 ____________
XX            CD             60.00                        XXXX.XX
XX            KEYBOARD       130.00                       XXXX.XX
XX            PRINTER        850.00                       XXXX.XX
XX            PEN DRIVE      65.00                        XXXX.XX
XX            SPEAKER        72.50                        XXXX.XX
                                                          ____________
                                                SUB TOTAL XXXX.XX
                                                TAX       XXXX.XX
                                                TOTAL     XXXX.XX



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
  Put the code you need help with here.
#include <iostream.h>
#include <conio.h>

int main()
{   float pCD,pkey,pprint,ppen,pspeak,qCD,qkey,qprint,qpen,qspeak,sub,tax,total;
    
    cout<<"QTY        DETAILS       UNIT PRICE           TOTAL PRICE       \n";
    cout<<"____       ______        _________            __________________\n";
    cin>>qCD;
    pCD=qCD*60.00;
    cout<<"           CD            60.00                "<<pCD<<endl;
    cin>>qkey;
    pkey=qkey*130.00;
    cout<<"           KEYBOARD      130.00               "<<pkey<<endl;
    cin>>qprint;
    pprint=qprint*850.00;
    cout<<"           PRINTER       850.00               "<<pprint<<endl;
    cin>>qpen;
    ppen=qpen*65.00;
    cout<<"           PEN DRIVE     65.00                "<<ppen<<endl;
    cin>>qspeak;
    pspeak=qspeak*72.50;
    cout<<"           SPEAKER       72.50                "<<pspeak<<endl;

    sub=pCD+pkey+pprint+ppen+pspeak;
    tax=0.03*sub;
    total=sub+tax;
    cout<<"                                              __________________\n";
    cout<<"                                   SUB TOTAL  "<<sub<<endl;
    cout<<"                                   TAX        "<<tax<<endl;
    cout<<"                                   TOTAL      "<<total<<endl;



    getch();
}
Last edited on
Gather all your input before you start outputting the bill on screen.

1
2
#include <iostream.h>
#include <conio.h> 

These are very, very outdated, and most compilers will refuse to have anything to do with them.

Don't use conio.h at all.

#include <iostream> is all you should have there.
like this? how can I get the output the question want?

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 <iostream.h>

int main()
{   
    float pCD,pkey,pprint,ppen,pspeak,qCD,qkey,qprint,qpen,qspeak,sub,tax,total;

    cout<<"QTY        DETAILS       UNIT PRICE           TOTAL PRICE       \n";
    cout<<"____       ______        _________            __________________\n";
    cin>>qCD;
    pCD=qCD*60.00;
    cout<<"           CD            60.00                "<<pCD<<endl;
    cin>>qkey;
    pkey=qkey*130.00;
    cout<<"           KEYBOARD      130.00               "<<pkey<<endl;
    cin>>qprint;
    pprint=qprint*850.00;
    cout<<"           PRINTER       850.00               "<<pprint<<endl;
    cin>>qpen;
    ppen=qpen*65.00;
    cout<<"           PEN DRIVE     65.00                "<<ppen<<endl;
    cin>>qspeak;
    pspeak=qspeak*72.50;
    cout<<"           SPEAKER       72.50                "<<pspeak<<endl;

    sub=pCD+pkey+pprint+ppen+pspeak;
    tax=0.03*sub;
    total=sub+tax;
    cout<<"                                              __________________\n";
    cout<<"                                   SUB TOTAL  "<<sub<<endl;
    cout<<"                                   TAX        "<<tax<<endl;
    cout<<"                                   TOTAL      "<<total<<endl;

}
like this?


No.

Here, look at this section of your code:
1
2
3
4
5
  cout<<"____       ______        _________            __________________\n";
    cin>>qCD;
    pCD=qCD*60.00;
    cout<<"           CD            60.00                "<<pCD<<endl;
    cin>>qkey;


See how you are outputting something, and then you're asking the user to input qCD, and then you're outputting something, and then you're asking the user to input qkey? Don't do that.

Get ALL the inputs before you start outputting the bill. All the cin before you start outputting the bill.
oooh

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 <iostream.h>

int main()
{   float pCD,pkey,pprint,ppen,pspeak,qCD,qkey,qprint,qpen,qspeak,sub,tax,total;

    cin>>qCD;
    pCD=qCD*60.00;
    cin>>qkey;
    pkey=qkey*130.00;
    cin>>qprint;
    pprint=qprint*850.00;
    cin>>qpen;
    ppen=qpen*65.00;
    cin>>qspeak;
    pspeak=qspeak*72.50;

    sub=pCD+pkey+pprint+ppen+pspeak;
    tax=0.03*sub;
    total=sub+tax;

    cout<<"QTY        DETAILS       UNIT PRICE           TOTAL PRICE       \n";
    cout<<"____       ______        _________            __________________\n";
    cout<<"           CD            60.00                "<<pCD<<endl;
    cout<<"           KEYBOARD      130.00               "<<pkey<<endl;
    cout<<"           PRINTER       850.00               "<<pprint<<endl;
    cout<<"           PEN DRIVE     65.00                "<<ppen<<endl;
    cout<<"           SPEAKER       72.50                "<<pspeak<<endl;
    cout<<"                                              __________________\n";
    cout<<"                                   SUB TOTAL  "<<sub<<endl;
    cout<<"                                   TAX        "<<tax<<endl;
    cout<<"                                   TOTAL      "<<total<<endl;

}
I'm trying to get the output to no avail haaa

1
2
3
4
5
6
7
8
9
10
11
12
QTY          DETAILS         UNIT PRICE                   TOTAL PRICE
______       ________        ____________                 ____________
XX           CD              60.00                        XXXX.XX
XX           KEYBOARD        130.00                       XXXX.XX
XX           PRINTER         850.00                       XXXX.XX
XX           PEN DRIVE       65.00                        XXXX.XX
XX           SPEAKER         72.50                        XXXX.XX
                                                          ____________
                                               SUB TOTAL  XXXX.XX
                                               TAX        XXXX.XX
                                               TOTAL      XXXX.XX
You are using outdated headers. I've modified your code and this worked for me, all I did was include the "using namespace std;" in order to define cin and cout or else it wouldn't compile and I added some output text to make it easier for the user to know what to input.
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
#include<iostream>

using namespace std;
int main()
{   float pCD,pkey,pprint,ppen,pspeak,qCD,qkey,qprint,qpen,qspeak,sub,tax,total;
	cout<<"How many CDs?\n";
    cin>>qCD;
    pCD=qCD*60.00;
    cout<<"How many keyboards?\n";
    cin>>qkey;
    pkey=qkey*130.00;
    cout<<"How many printers?\n";
    cin>>qprint;
    pprint=qprint*850.00;
    cout<<"How many pen drives?\n";
    cin>>qpen;
    ppen=qpen*65.00;
    cout<<"How many speakers?\n";
    cin>>qspeak;
    pspeak=qspeak*72.50;

    sub=pCD+pkey+pprint+ppen+pspeak;
    tax=0.03*sub;
    total=sub+tax;

    cout<<"QTY        DETAILS       UNIT PRICE           TOTAL PRICE       \n";
    cout<<"____       ______        _________            __________________\n";
    cout<<"           CD            60.00                "<<pCD<<endl;
    cout<<"           KEYBOARD      130.00               "<<pkey<<endl;
    cout<<"           PRINTER       850.00               "<<pprint<<endl;
    cout<<"           PEN DRIVE     65.00                "<<ppen<<endl;
    cout<<"           SPEAKER       72.50                "<<pspeak<<endl;
    cout<<"                                              __________________\n";
    cout<<"                                   SUB TOTAL  "<<sub<<endl;
    cout<<"                                   TAX        "<<tax<<endl;
    cout<<"                                   TOTAL      "<<total<<endl;

}
hmm it's because I use C++ borland the old one(?)... I copy it from my university's lab
mine can't use "using namespace std"
for now I'm here~~

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
#include <iostream.h>


int main()
{   float pCD,pkey,pprint,ppendrive,pspeaker,qCD,qkey,qprint,qpendrive,qspeaker,sub,tax,total;

    const float CD=60.00;
    const float key=130.00;
    const float print=850.00;
    const float pendrive=65.00;
    const float speaker=72.50;

    cout<<"Amount of CDs (per pack): ";
    cin>>qCD;
    pCD=qCD*CD;
    cout<<"Amount of keyboards: ";
    cin>>qkey;
    pkey=qkey*key;
    cout<<"Amount of printers: ";
    cin>>qprint;
    pprint=qprint*print;
    cout<<"Amount of pen drives: ";
    cin>>qpendrive;
    ppendrive=qpendrive*pendrive;
    cout<<"Amount of speakers: ";
    cin>>qspeaker;
    pspeaker=qspeaker*speaker;

    sub=pCD+pkey+pprint+ppendrive+pspeaker;
    tax=0.03*sub;
    total=sub+tax;

    cout<<"QTY        DETAILS       UNIT PRICE           TOTAL PRICE       \n";
    cout<<"____       ______        _________            __________________\n";
    cout<<qCD<<"          CD            60.00                "<<pCD<<endl;
    cout<<qkey<<"        KEYBOARD      130.00               "<<pkey<<endl;
    cout<<qprint<<"         PRINTER       850.00               "<<pprint<<endl;
    cout<<qpendrive<<"       PEN DRIVE     65.00                 "<<ppendrive<<endl;
    cout<<qspeaker<<"         SPEAKER       72.50                "<<pspeaker<<endl;
    cout<<"                                              __________________\n";
    cout<<"                                   SUB TOTAL  "<<sub<<endl;
    cout<<"                                   TAX        "<<tax<<endl;
    cout<<"                                   TOTAL      "<<total<<endl;

   
}


I got both the input format and the output format wanted in the black screen(output)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Amount of CDs (per pack): 5
Amount of keyboards : 120
Amount of printers : 35
Amount of pen drives : 236
Amount of speakers : 83


QTY          DETAILS         UNIT PRICE                   TOTAL PRICE
______     ________          ____________                 ____________
XX            CD             60.00                        XXXX.XX
XX            KEYBOARD       130.00                       XXXX.XX
XX            PRINTER        850.00                       XXXX.XX
XX            PEN DRIVE      65.00                        XXXX.XX
XX            SPEAKER        72.50                        XXXX.XX
                                                          ____________
                                                SUB TOTAL XXXX.XX
                                                TAX       XXXX.XX
                                                TOTAL     XXXX.XX


but.... is this how to 'create a customer’s bill for a company'??
Rather than lots of independent variables, I would suggest the use of arrays.
This should work even in Turbo C++3.0 for DOS

1
2
3
4
5
6
7
8
9
10
11
12
13
    const int size = 5;

    const char * name[size]  = { "CD", "KEYBOARD", "PRINTER", "PEN DRIVE", "SPEAKER" };
    const char * descr[size] = {"CDs (per pack)", "keyboards", "printers", "pen drives", "speakers" };
    const double price[size] = { 60.00, 130.00, 850.00, 65.00, 72.50 };
    int   qty[size]          = { 0 };

    int i;
    for (i=0; i<size; ++i)
    {
        cout << "Amount of " << setw(15) << descr[i] << ": ";
        cin  >> qty[i];
    }


Then output the headings for the bill. Loop through the arrays again, if the quantity qty[i] is greater than zero, calculate the cost for that line
qty[i] * price[i], add it to the subtotal and print out the item name name[i] and so on. And so on....

Last edited on
sorry... I didn't learn array yet, so I just use the variable one by one
anyway I already got how to do it... thanks for helping!
Topic archived. No new replies allowed.