Mar!o
Ok thanks
Mar!o
what about register unsigned num = 0u, last = 0u; for(;;) { ++last; num+=last; if(num + last > 100) { num = last; break; } }
Mar!o
then num should be the last number
Mar!o
even more simpler register unsigned last = 0u; for(register unsigned num = 0;;++num) {last+=num; if(num + last > 100) break; }
Cinappo
@reinterpret_cast For example #include <stdio.h> #include <math.h> main () int S; int V; S, V = 0; while (!S > 100) V = V + 1; S = S + V; printf ("The number is %d", V)
Cinappo
Can this be considered correct?
Cinappo
Only I don't know where to put parenthesis
Joesph
After while() {}
Cinappo
And after main() too
Anonymous
#include <stdio.h> #include <math.h> void main () { int S; int V; S=0,V = 0; while (S <100) { V = V + 1; S = S + V; } printf ("The number is %d", V); } Just a little edit. Might help
Dima
Thank you so much! What's void main?
entry point in your executable program
Cinappo
Another thing. On while(S>100) should I put the "!"?
Anonymous
Another thing. On while(S>100) should I put the "!"?
It's an unary operator so ,IT WILL only work with one operand. Here you can easily do while(S<100) Instead of while(!S>100) So and so
Anonymous
Thank you so much! What's void main?
In simple words ,every function has a return type(Must have) You can use either void(it doesn't return any value) or int(returns a value)
Anonymous
Oh thanks!!! So (S>100) without the exclamation mark is ok too?
Let's say you are using ! Which means NOT ,if I am right here to execute the while loop successfully. Condition you are trying to get is, While works till S is smaller than 100. So you can simply write it S<100. It will work just fine
Cinappo
Thanks, Sid!
Anonymous
Thanks, Sid!
☺️👍
Cinappo
Second program. I've wrote a flow chart. N is the number of values to insert, V the value you input, C the counter and S the sum. main() { int N, C; float V, S; N, C, V, S = 0; { gets(V); C = C+1; if(0<V<100); { S=S+V } printf("The sum is %d", S); }
Cinappo
Do the flow chart and the code have a sense? Sorry for bothering
Mat
Call S sum, V inputValue etc etc
Cinappo
Because that's how our teacher teaches us to define variables
Mat
Because that's how our teacher teaches us to define variables
That's a wrong (imo) way to define variables. They don't create a readable code
Cinappo
That's a wrong (imo) way to define variables. They don't create a readable code
Tell him, then. I can't do nothing, but thank you for telling me this.
Cinappo
I'm in the 4th year of scientific liceum (Italy) and we are still doing this. 3/4 of the class still don't understand this, and we've been doing algorithms, flow charts and pseudo-C since February-March (when we still were in the 3rd year...)
Cinappo
And in the code I forgot "gets(N);" after "N, C, V, S = 0"
Anonymous
Second program. I've wrote a flow chart. N is the number of values to insert, V the value you input, C the counter and S the sum. main() { int N, C; float V, S; N, C, V, S = 0; { gets(V); C = C+1; if(0<V<100); { S=S+V } printf("The sum is %d", S); }
void main() { int N, C; float V, S; N=0, C=0, S = 0; gets(V); /*(prefer it to input string,use scanf for INTEGER VALUES)*/ C = C+1; if(V>0&&V<100) /*don't terminate if and for loop statements */ { S=S+V; } printf("The sum is %d", S); }
Cinappo
Idk, but your help is precious anyways
Anonymous
Idk, but your help is precious anyways
You can use puts() too, But Don't forget about the scanf(). In long run it could also help.
Cinappo
We are used to scanf(%d, &n)
Anonymous
👍
yoav
even if i put "buffer" on the input its not printing "your good" what is the problem?
Ilya
even if i put "buffer" on the input its not printing "your good" what is the problem?
char* fgets( char* str, int count, std::FILE* stream ); Reads at most count - 1 characters from the given file stream and stores them in the character array pointed to by str. Parsing stops if a newline character is found, in which case str will contain that newline character, or if end-of-file occurs. If bytes are read and no errors occur, writes a null character at the position immediately after the last character written to str. The behavior is undefined if count is less than 1. It is also not specified whether a null character is written if count==1.
Anonymous
😂😂😂😂😂😂
Patel
😂
Marián
hey guys, i know that this question isn't really c++ specified but more likely wide-range, but still, how do you do your object designs?
Marián
i code complicated apps, games in opengl, backend apps and stuff, i don't have the issue to just lock at some specific problem and find solution for it, even if it takes hours of research, but what always melts my brain is object design, i can make it as good as possible, but going to bed thinking about programming i can always think of bit better design
Marián
do you use any apps like enterprise architect? did you learn any specific patterns like decorator / strategy / observer etc...? how do you approach your perfectly structured designs in your apps?
Ludovic 'Archivist'
hey guys, i know that this question isn't really c++ specified but more likely wide-range, but still, how do you do your object designs?
Simple, use the least amount of objects and of inheritance as you can; the least amount of Go4 design patterns as you can, and only ever yse any OO feature when it is absolutely without a doubt something that makes the code simple, shorter, or easier to understand
Ludovic 'Archivist'
I also take a very long amount of time thinking about what I am doing. This means that, in the project I have been designing lately, I have spent 95% of the time on the project thinking and designing, specifying aspects of the project, and 5% of my time actually writing code
Ludovic 'Archivist'
The code that is the simpler and easier to debug is the code that you do not write
...
/report
Liam
fixed
...
that was quick, youre either nocturnal or just live in a diff timezone than me :p
バレンタインがいない柴(食用不可)
Other than boost... do you guys suggest some other better tool to translate from date object to string and vice versa?
Ludovic 'Archivist'
This is by far the finest approach. Do you maintain a document for the design before coding?
Yes, a document that contain, cascading, the details of the needs, followed by a functional specification, followed by a technical specification, each containing potentially the mathematical demonstration of the algorithms used
Ludovic 'Archivist'
Other than boost... do you guys suggest some other better tool to translate from date object to string and vice versa?
Well, well, well, you are facing one of the worst problems in modern computer science. If your date object represent a timestamp, you will first want to know if it is a unix timestamp, a tai timestamp or any other form of timestamp. Then you will want to know if you want to consider leap seconds in your date representation as a string, as well as the daylight saving times, which you should, in theory, be able to access from your systems' date database
Ludovic 'Archivist'
Then you will want to correctly convert your timestamp into a date and apply all of the corrections related to the previously mentioned complication before printing it as a formated string
Ludovic 'Archivist'
Ludovic 'Archivist'
It is as easy as, let's say, converting IEEE floats to a string
...
Nah, definitely not hard /s
it really isn't, all you need to do is like get year / month / day / time and just replace the things you want to replace with the localization (if you even want that)
Ludovic 'Archivist'
Making a quirky, barely working implementation is easy
Ludovic 'Archivist'
Just like with a float to string implementation
Ludovic 'Archivist'
Making a correct one that will either be POSIX compliant (aka not scientifically correct) or that will follow correct conventions (being two way convertible) is remarkably complicated
...
true, but isnt that problem so small that it barely makes a difference?
...
also the only thing that you would need to handle i can think about is the leap year thing
Ludovic 'Archivist'
It can make all the difference in the ordering of operations of a database and crash everything
Ludovic 'Archivist'
if you go for a posix compliant, you will for example have twice the 59th second of the last minute of every year with a leap second
...
who is talking about a databse, also if youre ordering a databse, shouldnt u just be using the unixtime
Ludovic 'Archivist'
if you go for a posix compliant, you will for example have twice the 59th second of the last minute of every year with a leap second
if you go for an iso compliant one, you will have a 60th numbered second at the same time
Ludovic 'Archivist'
If you make a database, you need to use a steady time, unix time can go backwards and forward depending on leap seconds
Ludovic 'Archivist'
if a database uses unix timestamping, it is not consistent on operations done during a leap second if it ever stringifies time
Ludovic 'Archivist'
who is talking about a databse, also if youre ordering a databse, shouldnt u just be using the unixtime
This is from the specs of a database management system I am working on, note what time may look like in a distributed system The time is directed by the coordination server. Each server must synchronize to that time. The time is never guaranteed to be the real time, but it is guaranteed that any time query return value will be strictly greater than the highest recorded time of the server. When the system is running in normal and degraded state, the unit of the subtraction of timestamps is nanoseconds, else it is undefined.
...
oh okay, tbh, we should just come up with a better solution to get time into a number