I have some problems when I run this code and I don't know what to do to repair it. I want to create a code that lets you choose your car brand from an array.
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string MyCarBrandChose;
string my_car_brand = "NONE";
string CarBrandsArray[11] = { "MerchedsBenz", "BMW", "Audi", "Chitroen", "Ford", "Renault", "Pejeau", "RolsRoys", "MClaren", "Bentley", "Tesla" };
cout << "According to our datbase the most known car brands are ";
int NumberOfKnownCarBrands = sizeof(CarBrandsArray);
for (int i = 0; i < NumberOfKnownCarBrands; i++) {
cout << CarBrandsArray[i] << " ,";
}
cout << endl;
cout << "Enter your car brand\n->";
getline(std::cin, MyCarBrandChose);
for (int i = 0; i < NumberOfKnownCarBrands; i++) {
if (MyCarBrandChose == CarBrandsArray[i]) {
my_car_brand = CarBrandsArray[i];
}
}
if (my_car_brand == "NONE") {
cout << "Sory your brand is not in our list please double chech if you spelled the brand corectly and try again. Thank you!" << endl;
}
cout << endl;
cout << "Your car brand is " << my_car_brand;
cout << endl;
system("Pause");
}
The error occurs in this code in the standard library:
if (_State == ios_base::goodbit
&& _Ostr.rdbuf()->sputn(_Data, (streamsize)_Size)
!= (streamsize)_Size)
_State |= ios_base::badbit;
User contributions licensed under CC BY-SA 3.0