#Struggling with an assignment

1 messages · Page 1 of 1 (latest)

merry portal
#

I am completely new to coding and I have an assignemt I am lost on. I have been assigned to fix incorrect code and don't know how to.

clear orioleBOT
#

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.

river thunder
#

!f

clear orioleBOT
#
#include <stdio.h>
#define PI 3.14159
int main(void) {
  int radius;
  printf(“Enter radius :”);
  scanf(“% d”, &radius);
  printf(“volume is : % d \n\n“, 4 * radius * radius * radius / 3);
  return 0;
}
ArtemiZk
merry portal
#

thanks

river thunder
#

what do you have problems with

#

there are some obvious errors

river thunder
#

when you have an assignment they should have tought you something before?

muted zenith
#

you need to use "

river thunder
#

i am not OP

quaint cragBOT
#
Compiler Output
<source>:5:10: error: extended character “ is not valid in an identifier
    5 |   printf(“Enter radius :”);
      |          ^
<source>:5:25: error: extended character ” is not valid in an identifier
    5 |   printf(“Enter radius :”);
      |                         ^
<source>:6:9: error: extended character “ is not valid in an identifier
    6 |   scanf(“% d”, &radius);
      |         ^
<source>:6:12: error: extended character ” is not valid in an identifier
    6 |   scanf(“% d”, &radius);
      |            ^
<source>:7:10: error: extended character “ is not valid in an identifier
    7 |   printf(“volume is : % d \n\n“, 4 * radius * radius * radius / 3);
      |          ^
<source>:7:27: error: stray '\' in program
    7 |   printf(“volume is : % d \n\n“, 4 * radius * radius * radius / 3);
      |                           ^
<source>:7:29: error: stray '\' in program
    7 |   printf(“volume is : % d \n\n“, 4 * radius * radius * radius / 3);
      |                           
muted zenith
#

like i said

river thunder
muted zenith
#

that really really obvious

river thunder
#

yes

clear orioleBOT
#

@merry portal Has your question been resolved? If so, type !solved :)

merry portal
muted zenith
#

show code again

merry portal
#

!p

#

idk how to use the bot :/

#

one sec

muted zenith
#

!f

clear orioleBOT
#
#include <stdio.h>
#define PI 3.14159
int main(void) {
  int radius;
  printf("Enter radius:");
  scanf("%d", &radius);
  printf("volume is : %d \n\n", 4 * radius * radius * radius / 3);
  return 0;
}
ArtemiZk
merry portal
#

ok ok thanks

muted zenith
#

which error

muted zenith
#

bruh i hate it

#

;compile

2
#include <stdio.h>
#define PI 3.14159
int main(void) {
  int radius;
  printf("Enter radius:");
  scanf("%d", &radius);
  printf("volume is : %d \n\n", 4 * radius * radius * radius / 3);
  return 0;
}
quaint cragBOT
#
Program Output
Enter radius:volume is : 10
merry portal
#

here wait

#

./main.cpp:7:2: error: ignoring return value of function declared with 'warn_unused_result' attribute [-Werror,-Wunused-result]
7 | scanf("%d", &radius);
| ^~~~~ ~~~~~~~~~~~~~
1 error generated.
make: *** [Makefile:10: main] Error 1

merry portal
clear orioleBOT
merry portal
#

cool

merry portal
muted zenith
#

you can use std::ignore

#

for example

#
  std::ignore = scanf("%d", &radius);
merry portal
#

okay

#

thank you

low mason
#

lol😭

muted zenith
#

std::ignore moment

merry portal
#

?

muted zenith
# low mason idk that exists

but actually c++26 will just use

auto _ = scanf("%d", &radius);

@merry portal do not use this specificly, use above one

muted zenith
muted zenith
# low mason idk that exists

☟☟ Awesome T-Shirts! Sponsors! Books! ☟☟

Upcoming Workshops:
► C++ Best Practices Workshop, CppCon, Aurora, CO, USA, Sept 13-14, 2025: https://cppcon.org/class-2025-best-practices/
► C++ Best Practices Workshop, NDC TechTown, Kongsberg, NO, Sept 22-23, 2025: https://ndctechtown.com/workshops/c-best-practices/e8e3819af0f6

CLion is a...

▶ Play video
merry portal
muted zenith
#

ok, read error word by word with understanding

#

where error ocured?

merry portal
#

the uhm

merry portal
muted zenith
#

!code

clear orioleBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
merry portal
muted zenith
#

yup

#

but to be clear, can you show your build flags

merry portal
#

my what?

#

im sorry, i actually just dont know how to refer to like anything

muted zenith
#

ok, how you run your code, which ide do you use?

merry portal
#

like

#

the platform or whatnot i am writing and running the code in?

muted zenith
#

!google ide

clear orioleBOT
merry portal
#

replit

#

ive heard its bad (i can kinda tell) but its like very very short term

muted zenith
#

and anyway, can you show what you have on the folder structure?

merry portal
#

the course provided one but it was broken or something

merry portal
muted zenith
muted zenith
#

if no then clion, if yes then clion or Visual studio

merry portal
#

okay

merry portal
muted zenith
#

ok, open terminal

#

one time i installed doom emacs on replit

#

so that trivial anyway

merry portal
muted zenith
#

shell

#

tap to + and write shell

#

and that also called terminal on this thingy

merry portal
#

okay

#

done

muted zenith
#

the do ls -a

#
ls -a
#

and show output

muted zenith
#

tbf just install clion or vs

muted zenith
#

btw you not need #define PI anyway

#

there std::numbers::pi_v

wraith blaze
muted zenith
wraith blaze
#

And still, what about 0. What if there is no readable input?

muted zenith
muted zenith
#

again

#

but also problem with specificly radius

wraith blaze
muted zenith
#

if you not read radius then it not good

wraith blaze
#

So std::ignore takes care of these cases?

muted zenith
#

std::ignore , ignore assigment

#

litteraly

wraith blaze
#

Okay, cool, than it is unsafe, or not?

muted zenith
#

it safe

muted zenith
wraith blaze
#

Okay, will check it out, thx^^

south pumice
#

#include <stdio.h>
#define PI 3.14159
int main(void) {
int radius;
printf("Enter radius:");
scanf("%d", &radius);
printf("volume is : %d \n\n", 4 * radius * radius * radius / 3);
return 0;
}

!compile

muted zenith