consolidate all repos to one for archive
This commit is contained in:
61
semester_2/programiranje_2/naloga0102/zgled.cpp
Normal file
61
semester_2/programiranje_2/naloga0102/zgled.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void menu() {
|
||||
cout << "============================" << endl;
|
||||
cout << "=========== MENU ===========" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "1 ... GENERATE WATER INTAKES" << endl;
|
||||
cout << "2 ... PRINT WATER INTAKES" << endl;
|
||||
cout << "0 ... EXIT" << endl;
|
||||
cout << "============================" << endl;
|
||||
cout << "Select: ";
|
||||
}
|
||||
|
||||
void fillArray(float* array, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
array[i] = 0.5f + i * 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
void printArray(const float* array, const unsigned int size) {
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
cout << ((i > 0) ? ", " : "") << array[i];
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
const unsigned int days = 10;
|
||||
float* waterIntakes = new float[days];
|
||||
|
||||
srand(time(nullptr));
|
||||
|
||||
bool running = true;
|
||||
int selection;
|
||||
|
||||
do {
|
||||
menu();
|
||||
cin >> selection;
|
||||
switch (selection) {
|
||||
case 1:
|
||||
fillArray(waterIntakes, days);
|
||||
break;
|
||||
case 2:
|
||||
printArray(waterIntakes, days);
|
||||
break;
|
||||
case 0:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
cout << "Wrong selection!" << endl;
|
||||
break;
|
||||
}
|
||||
cout << endl;
|
||||
} while (running);
|
||||
|
||||
delete[] waterIntakes;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user