Why does it keep crahsing after I write "gold1" amount?

0 Karolis Kubilius · January 1, 2015
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int gold1, gold2, gold3;
    int avrage = (gold1+gold2+gold3)/3;
    printf("Eneter your gold amount.\n");
    scanf ("%d\n", gold1);

    printf("Eneter your teammates gold amount.\n");
    scanf ("%d\n", gold2);

    printf("Eneter your other teammates gold amount.\n");
    scanf ("%d\n", gold3);

    printf ("Your teams avrage gold amount is %d\n", avrage);

    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 Karolis Kubilius · January 1, 2015
What I was trying to say is why does is program ask me to write the "gold1" 2 times an "gold2, gold3" once like it should be and then gives me some random anwser.
+1 Bagel Cat · January 1, 2015
(FIXED, i think...)
- First problem: The program kept on crashing because you did not add the "&" symbol in-front of the variable name in the "scanf statement" 

- Second problem: The program wanted me to add 2 sets of numbers in the first "scanf" statement. 
The way I fixed this was just adding a [space] in-between the "quotation marks" symbol and the % symbol in the "scanf" statment, because C (the programming language) doest like the two symbols adjacent to each other (for some reason), and removing the "\n" in the "scanf" statement because it does not need it.

- Third problem: I moved the line of code where you defined "avrage" variable from the top because, when that line of code is placed above where the user defines the "gold" variables you get a really weird answer for the "avrage". I fixed this by placeing that line of code below the lines of code where the user defines the "gold" variables.


#include <stdio.h>
#include <stdlib.h>

int main()
{
int gold1, gold2, gold3, avrage;

printf("Enter your gold amount.\n");
scanf (" %d", &gold1);

printf("Enter your teammates gold amount.\n");
scanf (" %d", &gold2);

printf("Enter your other teammates gold amount.\n");
scanf (" %d", &gold3);

avrage = (gold1+gold2+gold3)/3;

printf("Your teams avrage gold amount is %d\n", avrage);

return 0;
}
0 Bagel Cat · January 1, 2015
If you have any more problems just let me know and I will try my best to fix them
0 Karolis Kubilius · January 1, 2015
I've writen in the "&" sings, but I still have that problem and I dont have any clues how to fix it and the answer is allways 2686736 no matter what I write in.
0 c student · January 2, 2015
in reference to your original code,
1. you have not initialized your gold variables meaning,
2. your average value had the calculated number of the trash data of the uninitialized variables,
3. your average value was never recalculated with the new gold data.
  • 1

C

103,706 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator