#Can anyone tell me what wrong with this code??

59 messages · Page 1 of 1 (latest)

full patrolBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

soft parrot
#

!f

full patrolBOT
#
#include <stdio.h>

int main() {
  for (int i = 0; i < 100; i++) {
    printf("Teknik Informatika YES\n");
  }

  printf("\nAngka kelipatan 5 antara 0-100:\n");
  for (int i = 5; i <= 100; i += 5) {
    printf("%d ", i);
  }

  printf("\n\nMasukkan jumlah perulangan: ");
  int n;
  scanf("%d", &n);

  int total = 0;
  printf("Masukkan %d nilai:\n", n);
  for (int i = 0; i < n; i++) {
    int nilai;
    scanf("%d", &nilai);
    total += nilai;
  }

  printf("Total penjumlahan: %d\n", total);

  return 0;
}
yuka *
soft parrot
#

Why do you think something is wrong?

somber trench
#

the int?

soft parrot
#

what?

#

what int?

somber trench
#

idk

#

sorry i new with this stuff

soft parrot
#

Does your code produce the result you want it to?

somber trench
#

no

#

its keep error

soft parrot
#

okay, then what's wrong with it?

#

what's the error?

somber trench
#

the code say this line is error

soft parrot
#

What does the error say?

somber trench
#

wait i forget

#

this

#

thats why idk about anything

soft parrot
# somber trench

Okay, that's saying that you compile with -std=c89 or -std=c90, which means you're using a standard that's been outdated for multiple decades by now

somber trench
#

ah

soft parrot
#

How do you compile your code?

somber trench
#

i use vcode compiler and falcon c++

#

that 2 also cannot run

soft parrot
#

VS Code doesn't have a compiler. It's just a text editor

somber trench
#

ah i see

tidal belfry
#

if you're intending to use C89 then you have to declare all variables at the top of a compound statement or at file scope

somber trench
#

so if i want to use the code

#

i must declare all the variable??

tidal belfry
#

;compile -ansi -pedantic-errorsc printf("h\n"); int x;

light sedgeBOT
#
Compiler Output
<source>: In function 'main':
<source>:5:1: error: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
    5 | int x;
      | ^~~
Build failed
somber trench
#

idk nothing about programing

#

fail?

long pendant
#

Declaring a variable is basically saying that this object exists. So when you write int x you're declaring that there is an int named x.
A compound statement is basically the stuff inside of the curly brackets.
C89 requires that all your declarations have to go at the top of a compound statement. So ```c
int main() {
printf("h\n");
int x;
return 0;
}

#

The reason your code isn't working is because you have declarations mixed in your code. You have to move those to the top of the function

#

Or you can compile with a newer standard, which would allow this mixing

somber trench
#

okayy

#

thank you for the help

dense sparrow
#

Is it a requirement for you to use a standard that's 35 years too old?

somber trench
#

i just follow my instructor

#

but still the code error

#

thats why i ask in here

#

idk iam wrong or my instructor are wrong

long pendant
#

You may have different versions of compilers, which would cause the default version that it compiles on to be different

dense sparrow
somber trench
#

okay

dense sparrow
somber trench
#

ah i see

#

well thank you guys for the help

#

!solved

full patrolBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

somber trench
#

idk how to fix it XD

#

this also for my homework T-T

#

can someone help me?