-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
112 lines (111 loc) · 2.44 KB
/
Copy pathmain.cpp
File metadata and controls
112 lines (111 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
using namespace std;
int main()
{
int option;
cout<<"Welcome to my first C++ program!"<<endl;
cout<<"Please select a task to perform (-1 to exit):"<<endl;
cout<<"1) Draw a pyramid"<<endl<<"2) Draw a star"<<endl<<"3) Compute the Fibonacci numbers"<<endl;
cin>>option;
while(1){
if(option==-1){
break;
}
else if(option==1){
int height;
cout<<"Please enter the height of the pyramid (between 1 and 40):"<<endl;
cin>>height;
while(1){
if(height>=1 && height<=40){
int row = 0;
while (row < height)
{
int count = 0;
while (count < height - row)
{
cout << " ";
count++;
}
count = 0;
while (count < 2*row + 1)
{
cout << "*";
count++;
}
cout <<'\n';
row++;
}
break;
}
else{
cout<<"You have entered an invalid value for height."<<endl;
cout<<"Please enter the height of the pyramid (between 1 and 40):"<<endl;
cin>>height;
}
}
}
else if(option==2){
int size;
cout<<"Please enter the size of the star (between 1 and 20):"<<endl;
cin>>size;
while(1){
if(size>=1 && size<=20){
int row=0;
while(row<2*size+1)
{
int column=0;
while(column<2*size+1)
{
if(row==column || row+column==(2*size+1) - 1){
cout << "*";
}
else{
cout << " ";
}
column++;
}
cout << "\n";
row++;
}
break;
}
else{
cout<<"You have entered an invalid value for size."<<endl;
cout<<"Please enter the size of the star (between 1 and 20):"<<endl;
cin>>size;
}
}
}
else if(option==3){
int n1=0, n2=1;
int sum=0;
int index,count=0;
cout<<"Please enter the index of the Fibonacci number to be computed:"<<endl;
cin>>index;
//largest index for fibonacci number: 48
//F(48)=512559680
while(1){
if(index>=0){
while (count<(index-1)){
sum=n1+n2;
n1=n2;
n2=sum;
count+=1;
}
cout<<"F("<<index<<")="<<sum<<endl;
break;
}
else{
cout<<"You have entered an invalid value for index."<<endl;
cout<<"Please enter the index of the Fibonacci number to be computed:"<<endl;
cin>>index;
}
}
}
else
cout<<"You have entered an invalid value for selection."<<endl;
cout<<"Please select a task to perform (-1 to exit):"<<endl;
cout<<"1) Draw a pyramid"<<endl<<"2) Draw a star"<<endl<<"3) Compute the Fibonacci numbers"<<endl;
cin>>option;
}
}