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

59 lines
1.2 KiB
C++
Raw Permalink 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-12-05 19:23:11 +01:00
#include <stdio.h>
2017-04-02 17:06:39 +02:00
int main()
{
2017-04-14 19:24:44 +02:00
short depth = 1;
2017-04-02 17:06:39 +02:00
std::string input;
2017-12-05 19:23:11 +01:00
printf("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-12-05 19:23:11 +01:00
if(depth<2 || depth==SHRT_MAX)printf("ERROR: Die Zahl ist zu gro\xE1 oder klein. Gib die Tiefe erneut ein: ");
2017-04-14 19:24:44 +02:00
}while(depth<2 || depth==SHRT_MAX);
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-12-05 19:23:11 +01:00
for(short idx = 0; idx<depth*depth; printf("*")) if(idx++%depth==0) printf("\n");
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-12-05 19:23:11 +01:00
printf("\n");
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-04-14 19:24:44 +02:00
for(short idx = 0; idx<depth; idx++)
2017-04-02 17:06:39 +02:00
{
2017-12-05 19:23:11 +01:00
printf("\n");
for(short idx2 = 0; idx2<idx; idx2++) printf(" ");
for(short idx2 = 0; idx2<depth*2-1-2*idx; idx2++) printf("*");
2017-04-02 17:06:39 +02:00
}
2017-04-08 17:51:54 +02:00
2017-12-05 19:23:11 +01:00
printf("\n\n");
2017-04-02 17:06:39 +02:00
2017-04-08 17:51:54 +02:00
2017-12-05 19:23:11 +01:00
for(short idx = 0; idx<depth-1; printf("\n"))
2017-04-02 17:06:39 +02:00
{
2017-12-05 19:23:11 +01:00
for(short idx2 = 0; idx2<depth-idx-1; idx2++) printf(" ");
printf("*");
for(short idx2 = 0; idx2<2*idx-1; idx2++) printf(" ");
if(idx++>0) printf("*");
2017-04-02 17:06:39 +02:00
}
2017-12-05 19:23:11 +01:00
for(short idx = 0; idx<2*depth-1; idx++) printf("*");
2017-04-14 19:24:44 +02:00
for(short idx = 0; idx<depth-2; idx++)
2017-04-02 17:06:39 +02:00
{
2017-12-05 19:23:11 +01:00
printf("\n*");
for(short idx2 = 0; idx2<2*depth-3; idx2++) printf(" ");
printf("*");
2017-04-02 17:06:39 +02:00
}
2017-12-05 19:23:11 +01:00
printf("\n");
for(short idx = 0; idx<2*depth-1; idx++) printf("*");
2017-04-02 17:06:39 +02:00
2017-12-05 19:23:11 +01:00
printf("\n\n\nProgrammende!");
2017-04-08 17:51:54 +02:00
getch();
2017-04-02 17:06:39 +02:00
return(0);
}