This repository has been archived on 2024-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
Schule/Sonstiges/Schleifen.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

2017-04-02 17:06:39 +02:00
#include<iostream>
#include<string>
#include<sstream>
2017-04-08 17:51:54 +02:00
#include<conio.h>
2017-04-02 17:06:39 +02:00
int main()
{
2017-04-05 17:28:45 +02:00
long long depth = 1;
2017-04-02 17:06:39 +02:00
std::string input;
2017-04-08 17:51:54 +02:00
std::cout << "Gib die Tiefe ein: ";
2017-04-05 13:45:29 +02:00
do
2017-04-02 17:06:39 +02:00
{
2017-04-05 13:45:29 +02:00
getline(std::cin, input);
std::stringstream(input) >> depth;
2017-04-08 17:51:54 +02:00
if(depth<2)std::cout << "ERROR: Die Zahl muss gr\x94\xE1 \ber als 1 sein. Gib die Tiefe erneut ein: ";
2017-04-05 13:45:29 +02:00
}while(depth<2);
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-04-10 16:31:26 +02:00
for(long long idx = 0; idx<depth*depth; std::cout << "*") if(idx++%depth==0) std::cout << "\n";
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-04-02 17:06:39 +02:00
std::cout << "\n";
2017-04-08 17:51:54 +02:00
2017-04-02 17:06:39 +02:00
for(long long idx = 0; idx<depth; idx++)
{
std::cout << "\n";
2017-04-08 17:51:54 +02:00
for(long long idx2 = 0; idx2<idx; idx2++) std::cout << " ";
for(long long idx2 = 0; idx2<depth*2-1-2*idx; idx2++) std::cout << "*";
2017-04-02 17:06:39 +02:00
}
2017-04-08 17:51:54 +02:00
2017-04-02 17:06:39 +02:00
std::cout << "\n\n";
2017-04-08 17:51:54 +02:00
2017-04-10 16:31:26 +02:00
for(long long idx = 0; idx<depth-1; std::cout << "\n")
2017-04-02 17:06:39 +02:00
{
2017-04-08 17:51:54 +02:00
for(long long idx2 = 0; idx2<depth-idx-1; idx2++) std::cout << " ";
2017-04-02 17:06:39 +02:00
std::cout << "*";
2017-04-08 17:51:54 +02:00
for(long long idx2 = 0; idx2<2*idx-1; idx2++) std::cout << " ";
2017-04-10 16:31:26 +02:00
if(idx++>0) std::cout << "*";
2017-04-02 17:06:39 +02:00
}
2017-04-08 17:51:54 +02:00
for(long long idx = 0; idx<2*depth-1; idx++) std::cout << "*";
2017-04-02 17:06:39 +02:00
for(long long idx = 0; idx<depth-2; idx++)
{
std::cout << "\n*";
2017-04-08 17:51:54 +02:00
for(long long idx2 = 0; idx2<2*depth-3; idx2++) std::cout << " ";
2017-04-02 17:06:39 +02:00
std::cout << "*";
}
std::cout << "\n";
2017-04-08 17:51:54 +02:00
for(long long idx = 0; idx<2*depth-1; idx++) std::cout << "*";
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
std::cout << "\n\n\nProgrammende!";
getch();
2017-04-02 17:06:39 +02:00
return(0);
}