C++ character check [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I have just started to learn C++ and i would like to get some help.
The user needs to type an ID number and the format has to be the following. The first character B and the other 4 any integer.
Im trying to check if the character format are right.
So far i have this:
if ((isalpha(id[0])=='B' ) && (isdigit(id.at(1))) && (isdigit(id.at(2))) ......
{
//do something
}
else
{
cout << "Wrong format" << endl;
}
but even if i type example B8745 it says wrong format.

You are comparing the result of isalpha, which is boolean, to character literal 'B'.

Related

Variable not declared in the scope error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 4 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Why am I getting this problem and how can I fix it? From my point of view I already declared it. Please see the image.
Thanks a lot!
You have an extra semicolon between the for statement and opening brace. That makes the for loop have an empty body, and the braced expressions have no idea what angle is supposed to be, since it truly is out-of-scope.

C++ if statement/xcode [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
For some reason, my "if" expression will not work in Xcode. It gives a "parse issue" with the if expression. Any suggestions? The error code is: "Expected unqualified-id". I am working with xcode. Please see below:
if (surfaceArea > 750)
{
totalCost t=50;
}
Thanks in advance,
if (surfaceArea > 750) //adding 50 dollars to cost if product is
//over 750 sq. inches
{
totalCost t+=50;
}
make a comment line // .
Hope you understood.
To write a multi line comment use /* .... */
Just remove over 750 sq. inches from your code. And use /* */ for multiline comments.

please suggest me what is wrong?? it only shows element not found [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
def binsearch(a,c):
first=0
last=len(a)-1
found=False
while first<=last and not found:
mid=(first+last)//2
if(a[mid]==c):
found=True
elif a[mid]<c:
last=mid-1
else:
first=mid+1
return found
a=list()
n=raw_input("Enter how many elements:")
for i in range(int(n)):
num=raw_input("Enter the elements:")
a.append(int(num))
c=raw_input("Enter the element u wanna search:")
b=binsearch(a,c)
if b:
print "Element",c,"found in position."
else:
print "Element not found."
The error is that c is a string.
Just add c = int(c) after the c = raw_input("...") line

My linked list is not working correctly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
following is my code for the program that will print out the random position contained values of nodes of a linked list. The problem is that my list is not printing the complete result. It prints only one result and thus. Please tell me where i am wrong.
int main(){
List* n;
int value=3;
int *counter=0;
collect(value,counter);
for(int i=0; i<&counter; i++);
{
count<<"\n Shuffled: "<< n.pickanddestroy();
}
}
Remove the semicolon at the end of the first line of your for loop.

Error: No Match for `Operator<<` [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So I'm creating this function as part of a larger program for my C++ course, and I am getting this error: no match for 'operator<<' followed by a bunch of gibberish whenever the compiler goes through this function
void print24hour(Time& start)
{
cout<<"The lecture starts at: ";
cout<<setfill('0')<<setw(2)<< start.getHours <<":"<<setfill('0')<<setw(2)<<start.getMinutes<<":"<<setfill('0')<<setw(2)<<start.getSeconds;
}
void print24hour(Time& end)
{
cout<<" and ends at: ";
cout<<setfill('0')<<setw(2)<<end.getHours<<":"<<setfill('0')<<setw(2)<<end.getMinutes<<":"<<setfill('0')<<setw(2)<<end.getSeconds<<endl;
}
Any solutions to my problem would be greatly appreciated
To get a function's return value you need to call it. Do this by appending parantheses to the member functions like end.getMinutes().