Large project how to seprate definition and declaration?
-
Excellent. Working fine now however I have to remove scanef_s. that _s was creating problem so i only remove _S and scanef remain as it. Now code working fine. Thank you for ur guidance. Now i got the clear idea how to write the code. I will copy the way you wrote this code. I am not a bad student however I like programming but problem is I think i am unable to think like a programmer. I am trying hard for that but no success yet :( I want to excel in this field but sometimes I stuck :((
We all get stuck at times :-) It is really pleasing to see you are willing to apply yourself to learn. None of us are born able to think like a programmer it is like any profession something you get good at by application of lots of time and effort. Your long single file code is sort of normal basic student level code, it works in a fashion. You are now seeking to move beyond that and I can only encourage that. All I did was really shorten up your code by making functions with more parameters and putting in error checking for things like typing letters instead of numbers etc. There are improvements you could do by using objects or classes but that is more stuff you are yet to learn. I looked up the problem with scanf_s it is they have changed security with this, you now need to use "%hu" rather than "%u" as meaning a pointer to an unsigned short. That tells you how many years since I have written code for a console application :-) So there are two fixes to remove the warning correctly
unsigned short iResult; // Define iResult as unsigned short not unsigned int
int err = scanf_s("%hu", &iResult); // Use %hu this should be error free on GCC
In vino veritas
-
We all get stuck at times :-) It is really pleasing to see you are willing to apply yourself to learn. None of us are born able to think like a programmer it is like any profession something you get good at by application of lots of time and effort. Your long single file code is sort of normal basic student level code, it works in a fashion. You are now seeking to move beyond that and I can only encourage that. All I did was really shorten up your code by making functions with more parameters and putting in error checking for things like typing letters instead of numbers etc. There are improvements you could do by using objects or classes but that is more stuff you are yet to learn. I looked up the problem with scanf_s it is they have changed security with this, you now need to use "%hu" rather than "%u" as meaning a pointer to an unsigned short. That tells you how many years since I have written code for a console application :-) So there are two fixes to remove the warning correctly
unsigned short iResult; // Define iResult as unsigned short not unsigned int
int err = scanf_s("%hu", &iResult); // Use %hu this should be error free on GCC
In vino veritas
You are right. i am completely new and it was my class assignment number 1. I finsihed it and submitted it already but then I came to know professionals never write everything in main that's why i decided to search in this direction. By your improved code I can see a boundery wall is set for wrong inputs. Which i wanted to set in my project as well but was not sure how to set those powerful boundaries as you set. I want to excel in this game of programming, I am not an extera ordinary student but i will keep on trying it day by day :) Following are few things I extracted from ur code which I am going to follow for the next time code or will at least try my best to do similar things. Correct me if I observed wrong. I did not follow the following things in my code. If I missed any point then point me that as well. 1) You are using braces by giving one space and starting 1st curly brace in-front of the statements like while and if. 2) All variable you wrote in small letters and to make them more clear u out _ sign to link them. 3) Function name 1st character and then the 2nd meaning name of function is capital. 3) 1 step indentation on each step involving in some kind of computation. 4) You used unsigned when you feel that value are in +ve.
-
You are right. i am completely new and it was my class assignment number 1. I finsihed it and submitted it already but then I came to know professionals never write everything in main that's why i decided to search in this direction. By your improved code I can see a boundery wall is set for wrong inputs. Which i wanted to set in my project as well but was not sure how to set those powerful boundaries as you set. I want to excel in this game of programming, I am not an extera ordinary student but i will keep on trying it day by day :) Following are few things I extracted from ur code which I am going to follow for the next time code or will at least try my best to do similar things. Correct me if I observed wrong. I did not follow the following things in my code. If I missed any point then point me that as well. 1) You are using braces by giving one space and starting 1st curly brace in-front of the statements like while and if. 2) All variable you wrote in small letters and to make them more clear u out _ sign to link them. 3) Function name 1st character and then the 2nd meaning name of function is capital. 3) 1 step indentation on each step involving in some kind of computation. 4) You used unsigned when you feel that value are in +ve.
correct on all counts, you have correctly identified that the standard makes the code much more easily readable and helps you identify errors. I enforce the standards at our company and I therefore never write without using that standard. The standard we use is essentially an extension of C99 or sometimes called ANSI-C standard and is used heavily in the sector I work, which is embedded programming. Companies in the game market you are looking at tend to use C++ (UNREAL GAME ENGINE etc) or C# (UNITY GAME ENGINE) and there standard may differ slightly as the majority of the code won't be C compliant, and they have other pressures for readability. So generally in large companies you will be expected to write to a standard and there will usually be a process to check code into the active repository. So while learning coding try and have your own standard but just remember you may have to adapt when you are employed. The company is not going to rewrite an entire repository to your standard even if you could argue it was better. So my standard is not the "absolute best" it's just a standard I would generally have to write to at work.
In vino veritas