I want to delete voltage coresponding to the device name. For example the earlier code deletes name only.I want to delete the voltage also, so that voltage will be subtracted from the total voltage.in easy words when device will be deleted its voltage will also be gone. i dont have any idea how to do it
cout << "Do you want to enter Devices (y/n)? ";
cin >> answer;
while (answer == 'y')
{
cout << "Enter Voltage threshold: ";
cin >> temp.volt;
if(temp.volt<50)
{
cout<<"system has enough voltage you may enter the device" ;
cout << "Enter device name: ";
cin >> temp.name;
cout << "Enter Consumption level in Percentage: ";
cin>>temp.consump;
cout<<"remaining battery";
bat=bat-(bat*temp.consump/100);
cout<<bat;
device.push_back(temp);
}
else {cout<<"sorry system dont have enough poewer" ;}
std::cout << "Do you want to enter more devices (y/n)? ";
std::cin >> answer;
}
cout << "Please enter name to remove:" <<endl;
std::getline(std::cin,who);
for( it=device.begin(); it!=device.end() ; ++it )
{
if( (*it).name == who ) //alternate: it->name ;)
{
//subtract device's voltage value from total voltage value here too!
device.erase(it); // iterator passed to erase
}
}
or just re-calculate the total voltage after removing the vector element