It's unfortunate there are audio issues (brief moments where audio gets cut off) but this video was very informative. Thank you. I'm tempted to write my own.
It's not you. I had this comment in the video description: "Apologies for the sound issues on this one. I recorded it immediately after last week's video, and I didn't realize my sound setup was causing issues. I'll fix it for the next video"
Yes, I think I had a video meeting app running in the background (not in a meeting, but the client was idle) and it was fighting for the mic. At least, that's what I suspect happened. I'll make sure the next video has better sound.
You mean the "int" on a separate line from "main(int argc, char **argv)" ? That's coding style preference. I learned it that way, when I first learned C, and it sort of stuck with me. You could also write it as "int main(int argc, char **argv)" and that would be fine too.
Hey i wrote this program to practice c the program tells a person how many boxes he can buy depending how much money the person has what do you think is there anything that can make this code better? #define BOX 6 Int main() { double dollars; double cost; printf("a box is $6 how many dollars do you have? "); scanf("%lf", dollars); cost = dollars / BOX; printf("you can buy %lf boxes", cost); return 0; }
When dealing with monetary values, float is fine; you don't need double. Also, you define BOX as 6 but don't use it in your first printf. You could write: printf("a box is worth $%f ... ", BOX); But note that BOX is meant to be a dollar value, so you probably want to define this as 6.00 so it's a float value. Also, boxes come in integer values, because that's a count. So you should be careful to only report an int value. One way to do this is by declaring: int count; Then: count = (int) ( dollars / box ); printf("you can buy %d boxes ", count); The (int) isn't strictly necessary here, since C will make the final value an int when it saves the result in count.
Why don't you use the *default* clause inside the switch statement for the unrecongnized operation? I would assume, that the compiler can optimize it better, when you use a default clause, instead of writing the default message outside of the switch statement.
I haven't tested optimization with/without "default" for this example. However, I can say that GCC will complain when compiling this program and you use "default" instead of letting the "switch" exit. So I avoided the compiler warning in this example.
Good question! I didn't use "NAN" for two reasons: 1. NAN may or may not be defined, and "is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN." But more importantly: 2. This was a quick math program, and there wasn't a need to return NAN. The program just does one operation and quits, so returning NAN doesn't really add value here. (And it prints an error anyway.)
@@freedosproject Thanks for the explanation. I had to look up quiet NaN since that's a term I'm not familiar with. I think a video explaining quiet NaN and signalling NaN would help for me to understand the concept better.
I assume you meant C ☺ I find C is pretty easy to learn. It has very few keywords, so it's fast to pick up. I taught myself C in college by reading a book.
If I ever get rich, I'm giving you 500K to make a modern DOS 64-bit, VESA graphics, Gigs of RAM, built in networking, no extenders, etc. I know, i know, here I am again. I'm telling you, there's a huge hole in the market for a debloated, stable, simple OS that works like DOS. Imagine banking systems, military, etc. Do they want to use windows? Probably not. Forced updates, instability, copious background processes constantly accessing the disk, so a power outage could result in corruption. Then there's Linux/Unix which is too complex and convoluted. Seeing hi-res text mode apps would be beautiful. It'd be like what we thought the future would look like in the 80s. I wish I was a smarter programmer, cause I would make it. I was stuck with real mode back when I tried to make my own OS. If you think it's a decent idea, you could let other programming friends know.
As a programmer who worken on DOS in the eighties for companies whoch included IBM, I can tell you that you don't need DOS for what you want to do. DOS was more of a hindrance than a help most of the time. It was just a rip-off of CP/M written in a hotel room by a Harvard dropout so could get a sweet deal through his daddy, and that's what the great US siftware industry was launched off. Makes Elon Musk's spaceport launchpads look like good engineering.
It's always a happy day when it starts with a retro programming session, it makes me think simpler and relaxes my brain muscles.
Thanks Jim,
Glad you enjoy it!
It's unfortunate there are audio issues (brief moments where audio gets cut off) but this video was very informative. Thank you. I'm tempted to write my own.
I thought the audio issue is just on my side (my ears in particular)
It's not you. I had this comment in the video description: "Apologies for the sound issues on this one. I recorded it immediately after last week's video, and I didn't realize my sound setup was causing issues. I'll fix it for the next video"
Yes, I think I had a video meeting app running in the background (not in a meeting, but the client was idle) and it was fighting for the mic. At least, that's what I suspect happened. I'll make sure the next video has better sound.
Even when atof does transform a string into the value 0 dot 0 you should check if the string given is a number with isdigit from ctype header.
That would be a good addition, especially to warn the user if they wrote "q13 + 12" (such as a typo)
❤Freedos The best Power
System❤Brazil❤
Thanks, glad you like it!
I'm wondering if the data type on a separate line before function name is just old convention or if this compiler needs that?
You mean the "int" on a separate line from "main(int argc, char **argv)" ? That's coding style preference. I learned it that way, when I first learned C, and it sort of stuck with me. You could also write it as "int main(int argc, char **argv)" and that would be fine too.
@@freedosproject Yes, that's what I meant. I see you did that with all your functions. That's what I like about C; it's flexible.
Hey i wrote this program to practice c the program tells a person how many boxes he can buy depending how much money the person has what do you think is there anything that can make this code better?
#define BOX 6
Int main() {
double dollars;
double cost;
printf("a box is $6 how many dollars do you have? ");
scanf("%lf", dollars);
cost = dollars / BOX;
printf("you can buy %lf boxes", cost);
return 0;
}
When dealing with monetary values, float is fine; you don't need double.
Also, you define BOX as 6 but don't use it in your first printf. You could write:
printf("a box is worth $%f ...
", BOX);
But note that BOX is meant to be a dollar value, so you probably want to define this as 6.00 so it's a float value.
Also, boxes come in integer values, because that's a count. So you should be careful to only report an int value. One way to do this is by declaring:
int count;
Then:
count = (int) ( dollars / box );
printf("you can buy %d boxes
", count);
The (int) isn't strictly necessary here, since C will make the final value an int when it saves the result in count.
@@freedosproject ok thank you.
Why don't you use the *default* clause inside the switch statement for the unrecongnized operation? I would assume, that the compiler can optimize it better, when you use a default clause, instead of writing the default message outside of the switch statement.
I haven't tested optimization with/without "default" for this example. However, I can say that GCC will complain when compiling this program and you use "default" instead of letting the "switch" exit. So I avoided the compiler warning in this example.
Instead of returning 0 for invalid operations and division by zero, wouldn't it be more appropriate to return NaN?
Good question! I didn't use "NAN" for two reasons:
1. NAN may or may not be defined, and "is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a quiet NaN."
But more importantly:
2. This was a quick math program, and there wasn't a need to return NAN. The program just does one operation and quits, so returning NAN doesn't really add value here. (And it prints an error anyway.)
@@freedosproject Thanks for the explanation. I had to look up quiet NaN since that's a term I'm not familiar with. I think a video explaining quiet NaN and signalling NaN would help for me to understand the concept better.
Someday I'll buckle down and learn C++. Someday..........
This isn't C++, it's C.
I assume you meant C ☺
I find C is pretty easy to learn. It has very few keywords, so it's fast to pick up. I taught myself C in college by reading a book.
Очень хороший бесплатный компилятор - Free Pascal, имеет мощную IDE. Зачем этот C? Только если вы предпочитаете этот язык?
I prefer C programming on DOS. It's what I know best. I'm not a Pascal programmer.
If I ever get rich, I'm giving you 500K to make a modern DOS 64-bit, VESA graphics, Gigs of RAM, built in networking, no extenders, etc. I know, i know, here I am again. I'm telling you, there's a huge hole in the market for a debloated, stable, simple OS that works like DOS. Imagine banking systems, military, etc. Do they want to use windows? Probably not. Forced updates, instability, copious background processes constantly accessing the disk, so a power outage could result in corruption. Then there's Linux/Unix which is too complex and convoluted. Seeing hi-res text mode apps would be beautiful. It'd be like what we thought the future would look like in the 80s.
I wish I was a smarter programmer, cause I would make it. I was stuck with real mode back when I tried to make my own OS. If you think it's a decent idea, you could let other programming friends know.
As a programmer who worken on DOS in the eighties for companies whoch included IBM, I can tell you that you don't need DOS for what you want to do. DOS was more of a hindrance than a help most of the time. It was just a rip-off of CP/M written in a hotel room by a Harvard dropout so could get a sweet deal through his daddy, and that's what the great US siftware industry was launched off. Makes Elon Musk's spaceport launchpads look like good engineering.
☺