I want to make a programm in which i will add a device, than i will add its voltage, at the end i will get the total voltage of the devices added. Now the problem is i am unable to get the input of devices and voltages at the same time. can someone help me ? I have written the code but it does this job in two seprate loops.
#include<conio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <string>
static int voltage;
using namespace std;
int main()
{
vector<string> device_name;
vector<int> device_voltage;
string name;
char answer;
int remove;
string rm;
cout << "Do you want to enter Devices (y/n)? ";
cin >> answer;
// Now that we have the number from the user,
// append it at the end of the vector
device_name.push_back(name);
cout << "Do you want to enter more numbers (y/n)? ";
cin >> answer;
}
// Now print all the values; notice that we didn't need to
// count how many elements were entered: we can always use
// the size() method to ask student_marks how many are there!
for (int i = 0; i < device_name.size(); i++)
{
cout << "Device #" << i+1 << '\t' << device_name[i];
}
// cout<<"Which device you want to remove " ;
// cin>>remove;
device_voltage.resize (device_name.size());
vector<string>::iterator s;
vector<int>::iterator m;
for (s = device_name.begin(), m = device_voltage.begin();
s != device_name.end();
++s, ++m)
{
do
{
cout << "Enter Voltage (0 to 100) for " << *s << ": ";
cin >> *m;
voltage+m;
if (*m < 0 || *m > 100)
{
cout << "Error: Voltage must be between 0 and 100" << endl;
}
}
while (*m < 0 || *m > 100);
}
if (!device_voltage.empty()) // equivalent to device_voltage.size() != 0
{
// cout << "There are " << count (voltage_device.begin(), voltage_device.end(), 100)
// << " students that got highest mark!" << endl;
while(...){
string name = get_a_single_device_name();
int voltage = get_a_single_device_voltage();
device_name.push_back(name);
device_voltage.push_back(voltage);
...
}