Deleting vector using user input

i want to delete items from vector and i want to take user input for doing so.kindly see the BOLD part of code. I want to delete the device and corresponding voltage at same time.


#include<conio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <string>

static int bat=100;
static int voltage;
using namespace std;

struct Device
{
std::string name;
int volt;
int consump;
};


int main()
{
std::vector<Device> device;
Device temp;
int vol=0;
char answer;
int rm;
//int consump;

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;
}

for(size_t i = 0; i < device.size(); ++i)
{
std::cout << "Device " << device[i].name;
std::cout << " Voltage: " << device[i].volt << std::endl;
voltage=voltage+device[i].volt;
}
cout<<"Total voltage : "<<voltage<<endl;
cout <<"Enter the name to delete \n" ;
cin>>rm;


device.erase(device.begin()+'rm');


// cout<<device.begin(0);
for(size_t i = 0; i < device.size(); ++i)
{
std::cout << "Device " << device[i].name;
std::cout << " Voltage: " << device[i].volt << std::endl;
}

getch();
return 0;
}
Topic archived. No new replies allowed.