Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int losowa(int przedzial);
- int wypisz(int x);
- int main()
- {
- int przedzial;
- int i = 0;
- int suma = 0;
- const int n = 5;
- int random[n];
- cout << "Program dodajacy 5 losowych liczb z wybranych przedzialow\n\n";
- for (i; i < n; i++)
- {
- cout << "Wybierz przedzial:\n\n [1] 1-100\n [2] 101-200\n [3] 201-300\n" << endl;
- cin >> przedzial;
- cout << "Wybrano przedzial: " << przedzial << "\n" << endl;
- if ((przedzial > 0) && (przedzial < 4))
- {
- cout << "Wylosowano: " << losowa(przedzial) << "\n\n";
- suma = suma + losowa(przedzial);
- cout << "Suma po " << i + 1 << " losowaniu = " << suma << "\n\n";
- random[i] = losowa(przedzial);
- }
- else
- {
- cout << "Nie ma takiego przedzialu" << endl;
- cout << "Suma nie ulegla zmianie = " << suma;
- cout << "\n\n";
- i = i - 1;
- }
- }
- cout << "Wylosowane liczby: " << endl;
- for (i = 0; i < n; i++)
- {
- cout << random[i];
- if(i != n - 1)
- {
- cout << ", ";
- }
- }
- cout << "\n\n";
- cout << "Suma wszystkich losowan = " << suma << "\n\n";
- system("pause");
- return 0;
- }
- int losowa(int przedzial)
- {
- srand(time(NULL));
- if (przedzial == 1)
- {
- return (rand() % 100) + 1;
- }
- else if (przedzial == 2)
- {
- return (rand() % 100) + 100;
- }
- else if (przedzial == 3)
- {
- return (rand() % 100) + 200;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement