line 47 (in my code) is not working becaues of getline?

I need some help. I enter a name company "International Business Machine" and a symbol "IBM" when I am prompted. However, you see 47 line, cout << a << "(" << t << ")" << endl;. "a" should have printed out a screen, "International Business Machine" but this is not working. I wonder why. I hope you can help me out.

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
//Author: Arthur James
//Lab 02: Buying and Selling Stocks

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;


int main ( )
{
   string a, t ; 
   string name;
   const double RATE = 0.020427;
   double PURCHASE;
   double share;
   double total;
   double totalcommission;
   double pricepershare;
   const double COMMRATE = .0185;
   double total1;
   double total2;
   double total3;
   double total4;
   double suck;
   
    cout << "Purchase price per share: ";
    cin >> PURCHASE; 
    
    cout << "Enter number of shares purchased:";
    cin >> share; 
    
  
    cout << "Enter name of company: ";
    getline(cin,a);
    
    cin.ignore (1000, '\n'); 
        
         
    cout << "Enter symbol: ";
    getline (cin,t);
    
    cout << endl; 
    
         
    cout <<  a << "(" << t << ")" << endl;
    
    cout << setw(9) << fixed << showpoint << setprecision(2)<< share * PURCHASE << endl;
    total = share * PURCHASE;
    cout << setw(9)<< setprecision(2)<< RATE * total << endl;
    totalcommission = RATE * total;
    cout << setw(9)<< setprecision(2)<< totalcommission + total << endl;
  
    total4 = totalcommission + total;
    
    cout << endl; 
    
    cout << "Selling price per share: " ; 
    cin >> pricepershare;
    
    //total1 = pricepershare * share; // Price per share times total of purchase
           
    cout <<setw(9) << fixed << showpoint << setprecision(2)<< pricepershare * share << endl; //
    
    total1= pricepershare * share;
    
    cout << setw(9)<< setprecision(2)<< total1 * COMMRATE << endl;
    
    total2 = total1 * COMMRATE;
    
       
    cout << setw(9)<< setprecision(2)<< total1 - total2 << endl;
    
    total3 = total1 - total2;
      
    cout << endl; 
    
    cout << "The profit or loss is " << total3 - total4 << endl;
    
    cout << endl;
   
    system ("pause");
    return 0;
}
Last edited on
Move line 38 to 33.

BTW, if you plan to use system ("pause");, make sure you #include <cstdlib> . However, http://www.cplusplus.com/forum/articles/7312/

I also recommend you use better variable names than a and t to represent the company_name and company_stock_symbol.

Hope this helps.
Topic archived. No new replies allowed.