ברני
ברני
That's what I build and I don't understand what's wrong
ברני
Maybe I forgot something?
ברני
Or it's not ligle to do else if in a row?
M.Khorram
the if() {...} else if() {...} is correct
ברני
the if() {...} else if() {...} is correct
And the resrt else if are not?
MengShu
If you ran into a problem when building this code. I guess the problem is caused by scanf. By default, scanf will be marked as unsafe function and the compiler will suggest you to use scanf_s
MengShu
This is the behavior of MSVC and I don't know if gcc or other compilers do this.
ברני
It says it used
MengShu
Could you send the error message to us?
ברני
ברני
Do maybe newM=married;?
M.Khorram
oops the variables are not initialized
MengShu
First, change the type of main from void to int. Then, set initial value to your three variables like age = 0, gender = 0 and married = 0.
MengShu
I think this should fix the issues.
ברני
V01D
You cannot return 0 from a void function btw. Also just use char and int pointers
ברני
You cannot return 0 from a void function btw. Also just use char and int pointers
But pointer is when you want to save it in the computer no?
Pavel
there's a typo pritnf
Andrew
you wrote pritnf instead of printf
V01D
A Pointer holds the memory address of the variable
ברני
you wrote pritnf instead of printf
Fixed but still same error
Pavel
Fixed but still same error
Can you paste the new code and the new error
ברני
Sec
olli
please use pastebin servicse or https://godbolt.org/ instead of sharing screenshots
ברני
https://onlinegdb.com/B1JgHKpwv
ברני
ברני
Maybe I should learn from another site? 😞
Andrew
the compiler dont let you use uninitialized values
olli
https://onlinegdb.com/B1JgHKpwv
scanf(" %c", &gender); you need to pass a pointer to the variable you want to write to Also, prefer int main() over void main() https://godbolt.org/z/1nPhMT
olli
Why prefer int over void? (doing what a friend told me didn't get the difrence)
because strictly speaking void main is not part of the official C/C++ programming language specification. Yes, a lot of compiler support it, but the standard says it shall be either int main(void) or int main(int argc, char *argv[])
olli
And pointer is not only for the memory?
Yes, but scanf basically reads a value and you need to tell it the memory location where to write it to
ברני
Yes, but scanf basically reads a value and you need to tell it the memory location where to write it to
Oh, OK.. Cus till now I didn't use pointers, I didn't even got to the quiz to do them
ברני
Is it OK if I'll ask you to write me an exemple so I'll fix it and learn what I did wrong?
Pavel
olli
Is it OK if I'll ask you to write me an exemple so I'll fix it and learn what I did wrong?
what kind of example do you want? this is your fixed code - https://godbolt.org/z/1nPhMT
Anonymous
RAII what is that?
Everything good about C++ since 1998
V01D
Initialize the variables
Anonymous
olli
You didn't use pointers
this uses pointers and passes them to scanf? scanf(" %c", &gender); printf("\n What's your age?\t"); scanf("%d", &age); printf("\n Are you Married?(y/n):\t"); scanf(" %c", &married);
ברני
The & was all the problem?
ברני
I don't get it, I've been told no need on char and I even tried with and with out
ברני
Maybe it was before I fixed the printf mistake 🤦‍♂
olli
The & was all the problem?
well, and int main instead of void main
ברני
V01D
well, and int main instead of void main
Yeah or dont return a value
olli
Yeah or dont return a value
I prefer not to use the "void main" compiler extension :)
MengShu
the problem may be the space before %c?
MengShu
' %c' needs 2 bytes to save the value, and gender is 1 byte character
MengShu
So the compiler told you that you need to use char*
MengShu
Is it right?
Lorenzo
For who do competition programming: why most people prefer vs code insteqd of visual studio? Visual studio debugger and intellisense looks better..
Anonymous
Ok thank you
MᏫᎻᎯᎷᎷᎬᎠ
I prefer not to use the "void main" compiler extension :)
I noticed that some programming languages doesn't has a return statement in the main function like java and Rust? Doesn't the os needs the state of the program in those ones or what?! Is it basically necessary?
MᏫᎻᎯᎷᎷᎬᎠ
I think Java has return.
public static void main(String...)
Talula
public static void main(String...)
Oh you mean to terminate the application? Well even C#, Python, Pascal doesn't have any termination, when the code ends it is considered that it is terminated.
MᏫᎻᎯᎷᎷᎬᎠ
Has this something to do with their runtime environment?
Talula
Yeah I know But why not just ordinary return 0; for the OS?
Because first of all Java doesn't work with OS it works on a VM... secondly it's automatic.
MᏫᎻᎯᎷᎷᎬᎠ
There must be a valid reason for that
Talula
And Rust?! It is a system programming language
I have no clue about Rust... never used it.
MᏫᎻᎯᎷᎷᎬᎠ
I have no clue about Rust... never used it.
Well it doesn't has any vm or something related Just a pure assembly code Tho it's application sometimes return some value from the main
MᏫᎻᎯᎷᎷᎬᎠ
I found this on a reddit thread: Rust certainly could be designed to do this. It used to, in fact. But because of the task model Rust uses, the fn main task could start a bunch of other tasks and then exit! But one of those other tasks may want to set the OS exit code after main has gone away. Calling set_exit_status is explicit, easy, and doesn't require you to always put a 0 at the bottom of main when you otherwise don't care.
ברני
I gess I can't use it like this? I Tried to do a online friend book when you write a name it's says it's bio...
ברני
Maybe switch? Or I'm not holding right the chars?