pass a string value to a function in a class which is entered by user

how to pass a string value to a function in a class which is entered by user and already been initialized by constructor
in case 4 it doesn't ask to enter a string please tell me what is the problem
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
101
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
using namespace std;
class invoice{
      private:
              int partno,quantity,asd;
              float price;
              string description;
              public:
              int getpartno(){
                  return partno;
                  }
              int getquantity(){
                      return quantity;
                      }
              float getprice(){
                    return price;
                    }
              string getdescription(){
                     return description;
                     }
              int setpartno(int part){
                  partno=part;
                  }
              int setquantity(int q){
                  if(q<0)
                  q=0;
                      quantity=q;
                      }
              float setprice(float p){
                    if(p<0)
                    p=0;
                    price=p;
                    }
              string setdescription(string d){
                     description=d;
                     }
              void display(){
                   cout<<"\n--------------------------------------------------------------------------------";
                   cout<<"\nPart no is:                   "<<partno;
                   cout<<"\nQuantity of part is:          "<<quantity;
                   cout<<"\nPrice fo thr part is:         "<<price;
                   cout<<"\nDescription fo thr part is:   \n\t"<<description<<endl;
                   }
              void inv(){
                   cout<<"Total bill is:                "<<quantity*price;
                   }
              invoice(int pn,int qua,float pr,string des){
                          partno=pn;
                          quantity=qua;
                          price=pr;
                          description=des;
              }
              };
int main(){
    string description="It is the excel of mehran car and made by suzuki iso 19001 sertified";
    char z;
    int partno=120,quantity=21;
    float price=291.55 ;
    invoice in(partno,quantity,price,description);
    in.display();
    aa:
    cout<<"\nif you want to make some change in this info press number according to specific task----->>>>\n\t1.\tFor part no-->\n\t2.\tFor quantaty-->\n\t3.\tFor price-->\n\t4.\tFor Description-->\n\t5.\tFor continue-->\n";
    int i;
    cin>>i;
    switch(i){
              case 1:
                   cout<<"Enter new part no:";
                   cin>>partno;
                   in.setpartno(partno);
                   break;
              case 2:
                   cout<<"Enter new Quantity:";
                   cin>>quantity;
                   in.setquantity(quantity);
                   break;
              case 3:
                   cout<<"Enter new price:";
                   cin>>price;
                   in.setprice(price);
                   break;
              case 4:
                   cout<<"Enter new description:";
                   getline(cin,description);
                   in.setdescription(description);
                   break;
              default:
                      cout<<"\nContinued without making any change\n";
                   break;
                   }
    in.display();
    cout<<"If you stil want some change then press \"p\":";
    cin>>z;
    if(z=='p')
    goto aa;
    in.inv();
    getch();
    return 0;
}
Have you read any input with cin>> before that? A '\n' could be left in the buffer which causes getline() to see the end of user input.
thax i have solved the problem that was not this
Topic archived. No new replies allowed.