for loops and arrays not displaying intended output

Hey, I'm new in C++ and not really sure about the ropes of c++. I sincerely hope you can help me out with this problem.

I'm working on an assignment, and have completed the c++ codes. but when I run the program, some outputs do not tally with my desk check.

briefly, the assignment is to output a shopping bill to a limit of 3 items.
there are 4 inputs : ID, item, qty and price per unit.
the outputs are : ID, item, qty, price per unit, total price of each item, the grand total, received payment and calculated balance.

using for loops, accessing the arrays, the output for qty for the 2nd and 3rd item fail to output properly.. how is that so?

here are the codes :
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include<iostream>
#include<iomanip>
#include<conio.h>
using namespace std;

char id[10][20];
char item[10][20];
double price[10];
int quantity[10];
double sale[10];
double pay_in,total_sale;

void bill();
void quantity_billing();

int main()
{
    int i;    
    

    for (i=0; i<3; i++)
    {
        cout<<endl;
        cout<<"ID: ";
        cin>>id[i];
        cout<<"Item: ";
        cin>>item[i];
        
        loop:
        cout<<"Price: ";
        cin>>price[i];
        
         if (price[i] <= 0)
           { cout<<endl;
             cout<<".....Invalid price....\n"<<"Re-enter ";
             goto loop;
           }       
          
        quantity_billing();
    }
    system("cls");
    bill();
    getch();
   return 0;
}



void bill()
{
     loop:
      int i;
      total_sale = 0;
      cout<<"ID"<<setw(20)<<right<<"Item"<<setw(18)<<right<<"Price"<<setw(15)<<right<<"Qty"<<setw(10)<<right<<"Sale"<<"\n"<<endl;
      
      for (i=0; i<3; i++)
      {
          cout<<setw(18)<<left<<id[i];
          cout<<setw(17)<<left<<item[i];
          cout<<setw(1)<<left<<"$"<<setw(7)<<right<<fixed<<setprecision(2)<<price[i];
          cout<<setw(12)<<right<<quantity[i];
          cout<<setw(7)<<right<<"$"<<setw(7)<<right<<fixed<<setprecision(2)<<quantity[i]*price[i]<<endl;
          
          sale[i] = (quantity[i]*price[i]);
          total_sale += sale[i];
      }
      

      cout<<endl;
      cout << "Total Sales:"<<setw(12)<<right<<"$"<<setw(8)<<right<<total_sale<<endl;
      cout << "Received Payment:"<<setw(8)<<right<<"$ ";
      cin>>pay_in;
       while (pay_in<=total_sale)
          {
               cin.ignore();   
               cout<< endl;                
               cout<< "Invalid payment amount...\n";
               cout<< "Press enter to continue.";
               cin.get();
               system ("CLS");
               goto loop;
          }     
      cout << "Balance:"<<setw(16)<<right<<"$"<<setw(8)<<right<<(pay_in-total_sale)<<endl;
         
      
}


void quantity_billing()
{    int i;
     loop:
       cout<<"Quantity: ";
       cin>>quantity[i];   
        if (quantity[i]< 0)
           { cout<<endl;
             cout<<".....Invalid quantity....\n"<<"Re-enter ";
             goto loop;
             }         
        cout<<"\n";
}



sorry guys, as i said, i'n new here.. pardon me if i'm doing anything wrong.
but do do do help with this problem. i can't see where i went wrong
I would remove the quantity_billing() function, if I've understood this correctly, and then change lines 29-39 to the following:

1
2
3
4
5
6
cin >> price[i];
while(price[i] <= 0) {
	cout << endl;
	cout << "Invalid price\nRe-enter:\t";
	cin >> price[i];
}


Or something like that. This is pretty good for a c++ beginner:) Let me know how it works out.
hey fafner, thank you so much for your help!! although, i kind of revamped the codes and throw in some input validation. it is a perfect 10 out of 10 i'd say :)
Topic archived. No new replies allowed.