4 errors.

Hi i am very new to programing and I just wrote my second ever code and am getting some strange errors. The error i am getting in line 38 is "error: expected ";" before string constants. In line 45 "error: expected '}' before 'else' in line 50 "expected ';' before '{' token and in line 201 "expected '}' at end of input. If you could help me with any of these errors it would be greatly appreciated. if you can't understand what the program is supposed to do just let me know

#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

int main (void)
{
int a;
int b;
int c;
int i;
int g;
int j;
int h;
int s;
int t;
int v;
int sum;
int mainChoice;
int numCheck;
int nthRank;
int sumBound;
int yz;

cout << "Lucas Numbers Calculator" << endl;
cout << "1. To find if a number belongs in the series or not." << endl;
cout << "2. To find the n-th number in rank." << endl;
cout << "3. To compute the sum of all lucas numbers up to a given bound." << endl;
cout << "4. To check if a given two digit number is a Carol number.";
cout << "Please choose: ";
cin >> mainChoice;

if(mainChoice == 1){
cout << "Please give the number you want to check: ";
cin >> numCheck;
if(numCheck== 1 or 2 or 3){
cout << numCheck "IS a Lucas Number.";
}

a=2; //first number
b=1; //second number
c=3; //next number

else if(numCheck<=0){
cout << "Only positive numbers are accepted.";
}

else(numCheck>3)
{

while(c<numCheck){
c=a+b;
a=b;
b=c;
}

if(c==numCheck){
cout << numCheck "IS a Lucas Number";
}

else() {
cout << numCheck "IS NOT a Lucas Number";
}

}

}//end mainChoice 1

else if(mainChoice == 2){
cout << "Please give the rank of the number you are looking for: ";
cin >> nthRank;

if(nthRank==1){
cout << "2 is the" nthRank"-nth number";
}

else if(nthRank==2){
cout << "1 is the" nthRank"-nth number";
}

else if(nthRank<=0){
cout << "Only positive numbers are accepted";
}

else (){

i=3;
d=2;
e=1;

while(i<=nthRank){
f=e+d
d=e
e=f
i=i+1}
}
do(){
cout << f "is the" nthRank"-th Lucas number.";
}

}//end mainChoice 2

else if(mainChoice == 3){
cout << "Please enter the upper bound of the summation you are looking for ";
cin >> sumBound

if(sumBound==1){
cout << "1 is the sumation of all Lucas numbers up to 1";}

else if(sumBound ==2){
cout << "3 is the sumation of all Lucas numbers up to 2";
}

else if(sumBound =<0){
cout << "0 is the sumation of all Lucas numbers up to 0";
}

g=2;
h=1;
else(sumBound<=3){

while(j<sumBound){
j=g+h
g=h
h=j
sum=sum+j}

do(){
cout <<sum "is the summation of all Lucas numbers until" sumBound;
}

}

}//end mainChoice 3

else if(mainChoice == 4){
cout << "Please give a two digit, positive number: ";
cin >> yz

if(yz<10 or yz>99){
cout << "Only two digit positive number are accepted";}

else if(){

s=2;
t=1;
v=3;
while(v<yz){
v=s+t
s=t
t=v
}

if(v==yz){

s=2;
t=1;
v=3;
while(v<y){
v=s+t
s=t
t=v
}
}

if(v==y){

s=2;
t=1;
v=3;
while(v<z){
v=s+t
s=t
t=v
}
}

do(){
cout << yz "IS a Carol number";
}

}
else(){
cout << yz "is NOT a Carol number";
}




}//end mainChoice 4

else if(mainChoice == 0){
system(PAUSE)
}

else(){
cout << "Wrong choice. Please choose again.";
}

}//end main

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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
 #include <cmath>
 #include <cstdlib>
 #include <iostream>

 using namespace std;

 int main (void)
 {
 int a;
 int b;
 int c;
 int i;
 int g;
 int j;
 int h;
 int s;
 int t;
 int v;
 int sum;
 int mainChoice;
 int numCheck;
 int nthRank;
 int sumBound;
 int yz;

 cout << "Lucas Numbers Calculator" << endl;
 cout << "1. To find if a number belongs in the series or not." << endl;
 cout << "2. To find the n-th number in rank." << endl;
 cout << "3. To compute the sum of all lucas numbers up to a given bound." << endl;
 cout << "4. To check if a given two digit number is a Carol number.";
 cout << "Please choose: ";
 cin >> mainChoice;

 if(mainChoice == 1){
 cout << "Please give the number you want to check: ";
 cin >> numCheck;
 if(numCheck== 1 or 2 or 3){
 cout << numCheck "IS a Lucas Number.";
 }

 a=2; //first number
 b=1; //second number
 c=3; //next number

 else if(numCheck<=0){
 cout << "Only positive numbers are accepted.";
 }

 else(numCheck>3)
 {

 while(c<numCheck){
 c=a+b;
 a=b;
 b=c;
 }

 if(c==numCheck){
 cout << numCheck "IS a Lucas Number";
 }

 else() {
 cout << numCheck "IS NOT a Lucas Number";
 }

 }

 }//end mainChoice 1

 else if(mainChoice == 2){
 cout << "Please give the rank of the number you are looking for: ";
 cin >> nthRank;

 if(nthRank==1){
 cout << "2 is the" nthRank"-nth number";
 }

 else if(nthRank==2){
 cout << "1 is the" nthRank"-nth number";
 }

 else if(nthRank<=0){
 cout << "Only positive numbers are accepted";
 }

 else (){

 i=3;
 d=2;
 e=1;

 while(i<=nthRank){
 f=e+d
 d=e
 e=f
 i=i+1}
 }
 do(){
 cout << f "is the" nthRank"-th Lucas number.";
 }

 }//end mainChoice 2

 else if(mainChoice == 3){
 cout << "Please enter the upper bound of the summation you are looking for ";
 cin >> sumBound

 if(sumBound==1){
 cout << "1 is the sumation of all Lucas numbers up to 1";}

 else if(sumBound ==2){
 cout << "3 is the sumation of all Lucas numbers up to 2";
 }

 else if(sumBound =<0){
 cout << "0 is the sumation of all Lucas numbers up to 0";
 }

 g=2;
 h=1;
 else(sumBound<=3){

 while(j<sumBound){
 j=g+h
 g=h
 h=j
 sum=sum+j}

 do(){
 cout <<sum "is the summation of all Lucas numbers until" sumBound;
 }

 }

 }//end mainChoice 3

 else if(mainChoice == 4){
 cout << "Please give a two digit, positive number: ";
 cin >> yz

 if(yz<10 or yz>99){
 cout << "Only two digit positive number are accepted";}

 else if(){

 s=2;
 t=1;
 v=3;
 while(v<yz){
 v=s+t
 s=t
 t=v
 }

 if(v==yz){

 s=2;
 t=1;
 v=3;
 while(v<y){
 v=s+t
 s=t
 t=v
 }
 }

 if(v==y){

 s=2;
 t=1;
 v=3;
 while(v<z){
 v=s+t
 s=t
 t=v
 }
 }

 do(){
 cout << yz "IS a Carol number";
 }

 }
 else(){
 cout << yz "is NOT a Carol number";
 }




 }//end mainChoice 4

 else if(mainChoice == 0){
 system(PAUSE)
 }

 else(){
 cout << "Wrong choice. Please choose again.";
 }

 }//end main 

..is how you're supposed to post code (except yours should be properly formatted)
Line 37 : does not produce an error, but is wrong. It means (numCheck==1) or (2) or (3). On one side you have a comparison and on the other you have a constant, which always evaluates to true.
Line 38 : numCheck is an expression and "something" in an expression. You are never allowed to put two expressions one after another without any operator or a semicolon in between. These should have a <<.
Line 45 and 201 : There is an opening { on line 34 that is never matched
Line 50 : you wanted to have an "else if..." on line 49.
You have more similar errors in your code. I don't see why you are getting only 4..
There's no salvation for that program. Currently it looks like a template for an exercise à la "find the 100 hidden errors in this code". Start anew and make sure it compiles every few lines you write and that it runs correctly. Pay attention to your semicolons.
And use real variable names this time.
Last edited on
Other notations don't use 'or' for '||' and learn to write them correctly.

1
2
3
4
5
6
7
8
9
if(numCheck== 1 or 2 or 3){
 cout << numCheck "IS a Lucas Number.";
 }

// should be 
if( ( (numCheck == 1) || (numCheck == 2) || (numCheck == 3) ) )
{
     cout << numCheck  << " IS a Lucas Number." << endl;
}
Last edited on
Topic archived. No new replies allowed.