Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Autor: Pawel Koniarski
- // Data: 5 stycznia 2013 r.
- // Problem: wyswietlanie choinki z gwiazdek
- // Plik: choinka.cpp
- #include <iostream>
- #include <cstdio> // stara wersja: stdio.h
- using namespace std;
- int main()
- {
- int size = 0; // rozmiar choinki
- // podanie rozmiaru choinki przez uzytkowanika
- cout << "Podaj szerokosc choinki (liczba nieparzysta, minimum 5, maksimum 79): " << endl;
- bool check=false;
- do
- {
- while(!(cin >> size))
- {
- cin.clear();
- string str;
- cin >> str;
- cout << "Blad: \"" << str << "\" nie jest liczba. Sprobuj jeszcze raz." << endl;
- }
- if ((size%2)==0 || size<5 || size>79)
- cout << "Liczba nie jest poprawna. Sprobuj jeszcze raz." << endl;
- else
- check=true;
- } while(check==false);
- // *****************************************************
- // Rysowanie choinki
- for(int i=size,j=1 ; i>0 ; i-=2) // i - szerokosc choinki ; j - ilosc gwiazdek w linii
- {
- // wyswietlanie spacji przed gwiazdkami
- for(int n=((size-j)/2) ; n!=0 ; n--)
- {
- cout << " ";
- }
- // wyswietlanie gwiazdek
- for(int n=j ; n!=0 ; n--)
- {
- cout << "*";
- }
- j+=2;
- cout << "\n";
- }
- // **************************************************
- // Rysowanie pnia choinki
- for(int width=size/5, height=size/5 ; height!=0 ; height--)
- {
- // wyswietlanie spacji przed pniem
- for(int n=((size-width)/2) ; n!=0 ; n--)
- {
- cout << " ";
- }
- // wyswietlanie gwiazdek jako pien
- for(int n=width ; n!=0 ; n--)
- {
- cout << "*";
- }
- cout << endl;
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement