Program stopped working [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<windows.h>
int main(){
int iCount=1;
int min=999999;
int max=0;
int iSum;
int iAVG=0;
int iValue;
system("color 97");
for(iCount=1;iCount<36;iCount++){
system("cls");
SetConsoleTitle("chairs");
printf("\t\tCHAIR VALUES\n\n");
printf("\nPlease enter the value of chair#: %d.\n>>", iCount);
scanf("%d",iValue);
iSum+=iValue;
if(iValue<min){
min==iValue;
}
if(iValue>max){
max==iValue;
}
printf("\n\nThe minimum and maximum values entered are:\nminimum value>>%d\nmaximum
value>>%d", min, max);
getche();
}
(iAVG=iSum/iCount);
printf("\n\nThe average value of the entered chairs is: %d", iAVG);
getche();
system("cls");
printf("\t\t\nGOODBYE USER!");
}
I wrote this code, a c question. I compiled it within codeblocks, it was successfully compiled and executed. However, when i entered the first chair value, it says that"chairs.exe has stopped working. Im here trying to see what might have lead to this problem. Any can give me a helping hand?

You missed to add '&' in scanf
scanf("%d",iValue);
Should be
scanf("%d",&iValue); //<--- Notice '&'
And as pointed out by "Zev Eisenberg" in comments.
min = iValue //<-- Make sure you are using assignment operator here.

Related

I've installed the vs code extension Code Runner to help me run C language programs but it doesn't run my code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
#include <stdio.h>
#include <conio.h>
int main()
{
float a,b;
int c;
printf("Enter Number a\n ");
scanf("%f",&a);
printf("Enter num b \n");
scanf("%f",&b);
c=a+b;
printf("The sum is %d",c);
return 0;
}
The query has now been resolved ,thanks to the community at stack overflow ,I am a beginner in programming and have just started to learn c and didn't knew regarding this but now I have been banned to ask questions😥
you should change code runner output to the Terminal
go to vscode settings and search code runnrer : run in terminal and check it
video how to do it : https://www.youtube.com/watch?v=Mxao-84mypo

A function in printf in C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
How can I call a function that has printf in it - in printf BUT without it printing the value entered twice?
in the code written below is how it is now, it prints the inserted value.
can I just use the function without printing the value again?
can I use printf(roll(num))
#include<stdio.h>
int roll(int);
int main()
{
int num;
printf("%d",roll(num));
return 0;
}
int roll(int a)
{
printf("Enter a number between 1-6:\n");
scanf("%d",&a);
while(a<1 || a>6)
{
printf("Wrong input! please enter a number between 1-6:\n");
scanf("%d",&a);
}
return a;
}
Just call the function without printf.
roll(num);

Bug in simple C source code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to know if the format of user defined function i wrote i.e return(xxx) is correct or not .
Because when i compile my code, i have to enter the input 2 times.It might be a silly mistake because i just began learning C language
****MY CODE:****``
#include<stdio.h>
long cube(long x );
long input,answer;
int main (void )
{
printf("Enter a number:");
scanf("%ld ",&input);
answer = cube(input);
printf(" The cube of %ld is %ld",input ,answer);
return 0;
}
long cube(long x )
{
return (x*x*x);
}
****ANswer****
#include <stdio.h>
long cube(long x);
long input, answer;
int main( void )
{
printf("Enter an integer value: ");
scanf("%d", &input);
answer = cube(input);
printf("\nThe cube of %ld is %ld.\n", input, answer);
return 0;
}
long cube(long x)
{
long x_cubed;
x_cubed = x * x * x;
return x_cubed;
}
remove the space after '%ld' it will take one input.
according your code,
scanf("%ld '&input) ;
here compiler at first wants one input for '%ld' then it waits for blank space you used after '%ld'. remove it then it will go next step after one input.
you should use,
scanf("%ld%",&input);

Is it possible for an if statement to say if something is not entered? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm doing a project and I'm just curious to know if it is possible to have a line that says "if something is not entered" and a prompt statement would be followed.
For example,
if(id_ == NULL){printf("John Doe is absent.")}.
Just a curious question because I want to explore C programming a bit more.
You can do this with scanf (or similar functions: fscanf, sscanf...).
Assuming id_ is an int:
if(scanf("%d",&id_)!=1){
printf("John Doe is absent.");
}
These functions return the number of input items successfully matched and assigned.
see top voted answer here for more info.
#include <stdio.h>
void input_id(int **id){
int num;
printf("input id:");
if(scanf("%d", &num)==1)
**id = num;
else
*id = NULL;
}
int main(void){
int id;
int *id_ = &id;
input_id(&id_);
if(id_ == NULL){
printf("John Doe is absent.\n");
} else {
printf("id : %d\n", id);
}
return 0;
}

Error : Find Largest Number in given numbers [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
This C program helps to find the largest number in given numbers but it is not working. I have highlighted the line where the problem is.
#include<stdio.h>
int main(){
int n,num,i;
int big;
printf("Enter the values of n: ");
scanf("%d",&n);
printf("Enter %d Numbers :",n);
scanf("%d",&big);
for(i=2;i<=n;i++){
scanf("%d",&num); //here is the problem..
//what it is reading as `num` without asking me to entering any thing ?
if(big<num)
big=num;
}
printf("Largest number is: %d",big);
return 0;
}
If you need the program to ask for input in a user-readable way, you can put
printf("Enter number #%d:",i+1);
before that line with scanf.
Anyway, the program will do its job just the same if you remove all printf's (and so, print no prompts, only wait for user input). They are only for users' convenience.
Your first scanf command only reads in your first number from stdin. The one on line 14 reads the rest, one per time around the loop. Then each one gets compared to variable "big", and replaces it it necessary.

Resources