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 1 year ago.
Improve this question
Why "if" is not accepting the condition (both "x" and "n" are constants after all).
#include <stdio.h>
int main(){
int x,n;
scanf("%d %d",&x,&n)
if(x==(4n-3))
printf("%d",x);
return 0;
}
Compile and you get this:
error: expected ';' before 'if'
4 | scanf("%d %d",&x,&n)
| ^
| ;
The little ^ points out the exact location of the bug and tells you to write a semi colon there. Go to that location that the compiler points out and do as it says.
Then:
error: invalid suffix "n" on integer constant
5 | if(x==(4n-3))
This means that 4n is nonsense, it is not valid C. You need to write 4*n-3.
You aren't writing a math statement here
It should be if(x==(4*n-3))
Related
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 2 years ago.
Improve this question
The top curly brace under int main(void) is what keeps getting flagged. The curly-brace cannot be the real issue because I know the entire code needs to be in between the curly braces, so it must be something else. I have tried deleting and replacing the braces, I have checked the other code to make sure all the loops have braces as needed... I don't get it. I have gone out and back int the program a few times over several days.
Here is the part of my code near the error message:
# include <cs50.h>
int main(void);
{
int h;
// prompt user until user enters an integer from 1 to 8
do
{
h = get_int("hight: \n");
}
while (h < 1 || h > 8);
You have a semicolon on
int main(void);
Remove the semicolon and you should be golden.
int main(void) {
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 4 years ago.
Improve this question
I am trying to use side effect operator in my expression which does not have just a variable. My program was compiled successfully but I got a runtime error "Segmentation fault"
Here is my code:
int main()
{
int x = 1;
printf(1 + (x++));
return 0;
}
C requires you to format the string, this way it knows what it should print. What you have in your example is nothing but memory addresses, which makes the C compiler confused.
int main()
{
int x = 1;
printf("%d\n", (1 + (x++)));
return 0;
}
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 5 years ago.
Improve this question
The below program when executed is printing ';' as output. I am not understanding why. When I am changing the value of 'c' and 'i', it is sometimes adding those two and sometimes printing symbols like '=' and ';'
#include<stdio.h>
int main() {
char c='1';
int i=10;
printf("%c", c|i);
}
Because 49 | 10 = 59 and 59 is the ASCII code of ';'.
It is performing the bitwise OR operation of 49(00110001) OR 10(00001010), which is 00111011(59) , and returning the ascii value of 59, please visit the page http://ee.hawaii.edu/~tep/EE160/Book/chap4/subsection2.1.1.1.html
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 6 years ago.
Improve this question
#include <stdio.h>
int main (void)
{
int hist,geo,phy,chem,bio;
int credits=0;
printf("Enter marks in history : ");
scanf("%d",&hist);
if(hist>40)
credits =10;
else
printf("No credits awarded for history");
printf("Credits obtained is %d",&credits);
return(0);
}
when I run the code, and I get a value of 230586 for the variable 'Credits'. Please help. I am a beginner in C
&x is like asking a question "What is the address of variable x?" , that's why you get the strange number. In order to print the variable value, please pass credits instead of &credits to the printf function.
printf("Credits obtained is %d", credits);
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
The following equation gives error message but it should not.
#include<stdio.h>
int main()
{
int a;
a=12 + 10/2 + 3*2 – 5;
printf("a=%d",a);
return 0;
}
What is wrong?
You wrote a dash – instead of a hyphen -. Spot the difference:
... 3*2 – 5;
... 3*2 - 5;
It seems that you have copied pasted the code from elsewhere. In expression
a=12 + 10/2 + 3*2 – 5;
^ is not minus sign
Change it to -
In your expression that's not a minus sign, judging by eye it's an en-dash, which is not accepted by the compiler. Don't write code in Word or "normal" word processors, use plain text editors.