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
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";}
#include <cmath>
#include <cstdlib>
#include <iostream>
usingnamespace 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
elseif(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
elseif(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";
}
elseif(nthRank==2){
cout << "1 is the" nthRank"-nth number";
}
elseif(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
elseif(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";}
elseif(sumBound ==2){
cout << "3 is the sumation of all Lucas numbers up to 2";
}
elseif(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
elseif(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";}
elseif(){
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
elseif(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.
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;
}