Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Diamond Display
- // This program uses nested loops to display a diamond.
- #include <iostream>
- using namespace std;
- int main()
- {
- int base=11;
- char symbol='*';
- int bcounter=1,rowcount=1;
- int toprows;
- int num=1;
- char answer;
- cout<<"Enter a number for the base of the triangle and a character for the symbol"<<endl;
- cin>>base;
- cin>>symbol;
- if(base%2==0)
- base++;
- //this code below generates the base of the triangle
- toprows=base/2;
- int symbolcount=base;
- if(cin)
- {
- while(rowcount<=toprows)
- {
- int spacecount=rowcount;
- while(spacecount<=toprows)
- {
- cout<<' ';
- spacecount++;
- }
- while(symbolcount>=base&&symbolcount>0)
- {
- cout<<symbol;
- symbolcount--;
- }
- num++;
- num++;
- symbolcount=symbolcount+num;
- cout<<endl;
- rowcount++;
- }
- while(bcounter<=base)
- {
- cout<<symbol;
- bcounter++;
- }
- toprows=base/2;
- char answer;
- cout<<"Would you like to quit the program? n for no q for quit"<<endl;
- cin>>answer;
- while(answer=='n')
- {
- symbolcount=base;
- num=1;
- bcounter=1;
- }
- }
- //loops to generate top rows of triangle not including the base
- cout<<endl;
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment