Answer the question
In order to leave comments, you need to log in
How to exit from input loop to string array?
Help to make an output from a loop of input of lines in an array. Let's say if the array is 200 long, and I only need to enter 5 cells, how can I interrupt it? break doesn't help or am I doing something wrong.
here is the code
#include <iostream>
#include <windows.h>
#include <string>
#include <vector>
using namespace std;
#define SIZE_VEC 5
class Summ
{
public:
void setSumm();
void getSumm();
private:
string *name = new string[SIZE_VEC]; //---надо сделать изменяемый размер массива
//vector<string> name;
};
void Summ::setSumm()
{
for (int i = 0; i < SIZE_VEC; ++i)
{
char en{ 'e' }; //
if (i == en) //------>Эта срань не работает
break; //
cout << i + 1 << " - ";
getline(cin, name[i]);
}
}
void Summ::getSumm()
{
for (int j = 0; j < SIZE_VEC; ++j)
{
cout << "Введите цену на " << name[j] <<": ";
float cost;
cin >> cost;
cout << name[j] << " - " << cost << endl;
}
}
int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
Summ sum;
sum.setSumm();
sum.getSumm();
system("pause");
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question