-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3297 from OlvadisHernandezLedesma/main
Reto #16 -C++
- Loading branch information
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
Retos/Reto #16 - LA ESCALERA [Media]/c++/OlvadisHernandezLedesma.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <iomanip> | ||
using std::string; | ||
using std::cout; | ||
using std::endl; | ||
using std::setw; | ||
using std::cin; | ||
|
||
void drawLadder(int n); | ||
void ladderpositiv(int n); | ||
void ladderNegativ(int n); | ||
|
||
int main() { | ||
int escalon; | ||
do { | ||
cout << "Ingrese el numero de escalones: "; | ||
cin >> escalon; | ||
|
||
if (cin.fail() || cin.eof()) { | ||
break; | ||
} | ||
|
||
drawLadder(escalon); | ||
} while (escalon); | ||
|
||
return 0; | ||
} | ||
|
||
void ladderNegativ(int n){ | ||
n=n*-1; | ||
string parte1="_", parte2="|_"; | ||
for(int i=1; i<=n; i++){ | ||
if(i==1) { | ||
cout<<parte1<<endl; | ||
} | ||
|
||
for(int j=1; j<=i-1; j++){ | ||
cout<<" "; | ||
} | ||
cout<<parte2<<endl; | ||
|
||
} | ||
} | ||
|
||
|
||
void ladderPositiv(int n){ | ||
string parte1="_", parte2="_|"; | ||
|
||
for(int i=n; i>=1; i--){ | ||
if(i==n) { | ||
for(int j=1; j<=i; j++){ | ||
cout<<" "; | ||
} | ||
cout<<parte1<<endl; | ||
} | ||
|
||
|
||
for(int j=1; j<=i-1; j++){ | ||
cout<<" "; | ||
} | ||
cout<<parte2<<endl; | ||
|
||
} | ||
} | ||
|
||
|
||
void drawLadder(int n){ | ||
if(n>0) { | ||
ladderPositiv(n); | ||
}else if(n<0){ | ||
ladderNegativ(n); | ||
}else{ | ||
cout<<"__"<<endl; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|