0

What is the problem in here? When I execute the code, it prints the model variable before I input the manufacturingCompany variable.

#include <iostream>
using namespace std;

class Smartphone{
public:
    string manufacturingComapny, model, screenType;
    int price, batteryCapacity;

    Smartphone(){
        cout << "Enter model: ";
        getline(cin, model);
        cout << "Enter screen type: ";
        getline(cin, screenType);
        cout << "Enter battery capacity: ";
        cin >> batteryCapacity;
        cout << "Enter price: ";
        cin >> price;
        cout << "Enter manufacturing company: ";
        getline(cin, manufacturingComapny);
        cout << model << endl;
        cout << screenType << endl;
        cout << batteryCapacity << "mA"<< endl;
        cout << price << "$" << endl;
        cout << "Made by " << manufacturingComapny << endl;


    }



};



int main(){
    Smartphone phone1;




}
463035818_is_not_a_number
  • 88,680
  • 9
  • 76
  • 150
  • Before `getline` do `cin >> std::ws;` or change `cin >> price;` to `cin >> price >> std::ws;` – Eljay Jul 15 '21 at 11:25

0 Answers0