if statement works with any input [closed] - c

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
i'm learning c programming language, i have been told to make a password code but whenever i compile it , it gives me "correct" even tho its not. this is my code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int s;
scanf("%d", &s);
if (s = 1234) {
printf("the password is correct");
} else {
printf("the password is incorrect");
}
return 0;
}
also can someone give me a link where they have beginner tasks for me ?
i enrolled in an embedded system course and i had no experience for C , so i was told to learn C 1st

I think you are using wrong the equal sign. It must be == not = in the if statement. Also you have to include
#include <stdio.h>

Related

C math on user input [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 last month.
Improve this question
I'm new to c and I'm trying to preform maths on a user input, specifically the year of a date.
When I try to divide , or do any maths on the variable 'y' and store it in 'fpy' it will always print the value '6422032' or close to it. Any help would be great, I've been trying for hours now.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
int d,m,f,y,spY;
//char y[3];
printf("Day from date calculator \n");
printf("Please enter the date in DD/MM/YYYY formate. For example , 1/7/1440 \n");
printf(">");
scanf("%d/%d/%i",&d,&m,&y);
int fpy = y/10;
printf("%d",&fpy);
return(0);
}
this
printf("%d",&fpy);
should be
printf("%d",fpy);

prototypes are correct but garbage values are displayed in the output [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 5 years ago.
Improve this question
The prototype (void example();) I have mentioned for the program is correct, but the compiler is giving garbage value instead of correct values in the output.
What codes should be added or removed?
Here is my code:
#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
void example()
{
static int x = 10;
x=x+10;
printf("\n%d",&x);
}
int main()
{
int i;
for(i=0;i<=3;i++)
{
example();
}
getch();
return 0;
}
You are using an adress of a variable where printf wants just the value:
printf("\n%d",&x);
->
printf("\n%d",x);
Your result might also be improved by using "%d\n" instead.

Dev C keeps returning a wrong value [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 5 years ago.
Improve this question
#include <stdio.h>
#include <stdlib.h>
main()
{
int n;
printf("Introduce un número entero\n");
scanf("%d", &n);
printf("Has introducido el número: %d", &n);
}
Every time I run this C code I get 6487628 for n, I have uninstalled and installed it over and over again and it keeps doing that, I don´t know what else to do.
You don't want the &n in the printf(), you want n. You are displaying the memory location n is stored in

I am getting absurd values for the variable 'credits' [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 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);

Why it doesn't work ( C Lang in Dev C++ ) [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
Please tell me, what is wrong here,it compiles but console crashes when i enter the number. I don't know what to write next, i will just write something to make my post possible.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
unsigned int i,l,p,w;
printf("Enter natural number excluding 0: ");
scanf("%d",l);
p = 1;
for(i=1;i<=l;i++)
{
p=p*i;
}
w=p;
printf("\nFactorial of entered number %d",w);
return 0;
}
scanf("%d",l); you need to insert the address of l, which is &l.
You should also use %u for unsigned ints, not %d.

Resources