Untitled
unknown
c_cpp
3 months ago
1.0 kB
12
Indexable
#include <vector>
#include <iostream>
using namespace std;
void showMenu()
{
cout << "[ 1 ] Wpisz liczbe do wektora\n"
<< "[ 2 ] Wypisz wektor\n"
<< "[ 3 ] Wyjdz z programu\n";
cout << endl;
}
void readNumbers( vector< int >& vec )
{
int number;
cout << "Podaj liczbe:\n";
cin >> number;
vec.push_back( number );
}
void showNumbers( const vector< int >& vec )
{
for( int i = 0; i < vec.size(); ++i )
{
cout << vec[ i ] << ", ";
}
cout << endl << endl;
}
int main()
{
vector< int > numbers;
bool isAppRunning = true;
while( isAppRunning )
{
showMenu();
int choice;
cout << "Wybierz opcje (1 - 3):\n";
cin >> choice;
switch( choice )
{
case 1:
readNumbers( numbers );
break;
case 2:
showNumbers( numbers );
break;
case 3:
cout << "Zakonczyles dzialanie programu." << endl;
isAppRunning = false;
break;
default:
cout << "Nie ma takiej opcji!" << endl;
break;
}
}
}
Editor is loading...
Leave a Comment