My linked list is not working correctly [closed] - c++

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.

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.

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

C++ character check [closed]

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'.

a Sequential that decreased by 5 using a for loop [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 8 years ago.
Improve this question
i want to print a Sequential that decreased by 5
using a for loop
but i don't know why it doesn't print the output :(
#include<bits/stdc++.h>
using namespace std;
int main(){
for(int j=60;j<=0;j-=5){
cout<<j<<endl;
}
}
whats the wrong?!
Change it to
for(int j=60;j>=0;j-=5){
^^

Solution to set precision errors [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 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.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
Where am I going wrong? I inclduded setprecision(2) but the output comes wrong.
example: if the sum is 23 and n is 10, the answer is 2.00
for(i=3; i<n; i++)
{
sum=sum+marks[i];
}
cout<<"Total marks of the student is "<<sum<<endl;
avg=sum/n;
cout.setf(ios::showpoint);
cout<<setprecision(2)<<fixed;
cout<<"Average marks of the student is "<<avg<<endl;
getch();
That's because you're using the integer division, in which the fractional part (remainder) is discarded.
Change
avg=sum/n;
to
avg=sum/(float)n;