Trying to decide which programming language I want to learn

Click For Summary
Choosing a programming language to learn can be challenging, especially for someone with a background in older languages like assembly, Fortran, and Pascal. C# and C++ are considered for firmware design, while Python is favored for its ease of use and relevance to gaming, particularly with grandchildren. C++ is noted for its speed and compactness, making it suitable for game programming, but it may require more effort to learn compared to C#. Resources like Visual Studio for C# and various online tutorials can help beginners get started, while microcontroller programming can be explored through platforms like Arduino and Raspberry Pi. Ultimately, the choice should align with personal interests in scientific or gaming applications.
  • #301
yungman said:
I solved the problem. It is the name of my whole project I created!
It's a good idea to create descriptive names for your projects, but not good to go overboard on the names. I have several hundred projects that I've created over the years, but they're short with no spaces, to remind me what the basic purpose of the program is. Instead of "3.29 read write to file ifstream ofstream open close," I would have called the project "FileOutput."
yungman said:
VS has strange things, I found the demofile.txt that created by the program now. Also VS is strange, I before I end up deleting the whole project, I tried to change the name of EVERY file inside, it's like every time I navigate around, I see new names that I missed the first time! It just did not work trying to rename the files, finally, I had to take out the source.cpp, then try to delete. Then I had to close all the other projects ( I had the ifstream project opened in another VS program) in order to even create the new 3.29 ofstream.

Now my other ifstream doesn't read the demofile.txt. That's another story for another day. I want to work on that first.
What you describe may or may not be strange. The only other C/C++ compiler I've used was Borland's product, close to 30 years ago.
If you don't provide the complete path to the file, where the file needs to be depends on whether you're running your program from the debugger or from a command prompt window.
If you're running from within the debugger, the input file or output file has to be in the same directory as the source code.
If you're running the program from a command prompt window, the input file or output file has to be in the same directory as the executable.

If you do provide the complete path to the input or output file, it doesn't matter where the file is -- the program can find the file.
 
Last edited:
  • Like
Likes sysprog and yungman
Technology news on Phys.org
  • #302
I am actually very excited on this input and output file, this, is a real interface to the outside world rather than staying in it's little cocoon. So if I want to save and open a file anywhere in the computer I can put
C++:
{
ofstream outputFile;
outputFile.open( C:\Users\alanr\Desktop\Alan amp3\SS\OPS\MOSFET\demofile.txt);
}
in order to save demofile.txt into C:\Users\alanr\Desktop\Alan amp3\SS\OPS\MOSFET?
 
  • Like
Likes sysprog
  • #303
yungman said:
I am actually very excited on this input and output file, this, is a real interface to the outside world rather than staying in it's little cocoon. So if I want to save and open a file anywhere in the computer I can put
C++:
{
ofstream outputFile;
outputFile.open( C:\Users\alanr\Desktop\Alan amp3\SS\OPS\MOSFET\demofile.txt);
}
in order to save demofile.txt into C:\Users\alanr\Desktop\Alan amp3\SS\OPS\MOSFET?
You need double quotes around the path and filename string, and because characters preceded by a backslash (\) are escaped, you need to double them up.
Code:
outputFile.open( "C:\\Users\\alanr\\Desktop\\Alan amp3\\SS\\OPS\\MOSFET\\demofile.txt");

Or you can use a single forward slash.
Code:
outputFile.open( "C:/Users/alanr/Desktop/Alan amp3/SS/OPS/MOSFET/demofile.txt");
 
  • Like
Likes sysprog and yungman
  • #304
It doesn't work, I can't find the file even though the program said it's done. this is my program.
C++:
// Read and write to file
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
    ofstream outputFile;
    outputFile.open("C:\Users\alanr\Desktop\C++ exercise\Gaddis\inout files\demofile.txt");
    cout << "Now writing data to the demofile.txt" << endl;
    outputFile << "Bach\n";
    outputFile << "Beethoven\n";
    outputFile << "Mozart\n";
    outputFile << "Schubert\n";

    outputFile.close();
    cout << "Done " << endl;
    cout << endl;
    return 0;

}

I search around, I can't find the file, it's not in the 3.29 folder.
I created the inout files folder and copy the address bar and add \demofile.txt to the end.
 
  • #305
I was looking at the message after compile, I don't see where the demofile.txt saved.
Compile error file write.jpg


The only thing I see in the program is the change of color as shown. It should all be RED, but the '\a' looks different. I googled, \a is alarm or alert. But alanr is the path in my computer, not much I can do.
Program question.jpg


thanks
 
  • #306
yungman said:
It doesn't work, I can't find the file even though the program said it's done
I explained why it doesn't work in post #303. Please read more carefully the posts where members are trying to help you out.
 
Last edited:
  • Like
Likes sysprog
  • #307
Mark44 said:
I explained why it doesn't work in post #303. Please read more carefully the posts where members are trying to help you out.
Thanks, got it.

I do the same thing using ifstream and point to the folder and read back successfully.

Thanks
 
  • Like
Likes sysprog
  • #308
From post #277:
yungman said:
I want the program to read in any character from the keyboard, display it and show the ASCII number. Then loop back to ask another character. I want it to exit when I hit ENTER ( ASCII = 10)
Here's a different version of what you were trying to do, written purely in C. It uses _getche(), whose declaration is in conio.h. It gets a character from the keyboard, and echoes it to the screen. A slightly different function, _getch(), doesn't echo the character.
C:
#include <cstdio>     // for printf()
#include <conio.h>    // for _getche()
#define CR 13         // <ENTER> key

int main()
{
    int userEntry;
    do
    {
        printf("Press any key:  ");
        userEntry = _getche();

        printf("\nYou hit: ");
        if (userEntry == CR) printf("<ENTER>\n");
        else printf("%c\n", (char) userEntry);
        printf("ASCII code: %d\n", userEntry);

    } while (userEntry != CR);
}
BTW, the ASCII code for the Enter key is 13 (Carriage Return). On Windows machines, when you press <Enter>, the OS inserts two characters -- CR and LF (carriage return and line feed, ASCII codes 13 and 10, respectively). On Linux and Macs (I believe), only one of these is inserted, but I don't recall which one it is.
 
  • Like
Likes sysprog
  • #309
Mark44 said:
From post #277:
Here's a different version of what you were trying to do, written purely in C. It uses _getche(), whose declaration is in conio.h. It gets a character from the keyboard, and echoes it to the screen. A slightly different function, _getch(), doesn't echo the character.
C:
#include <cstdio>     // for printf()
#include <conio.h>    // for _getche()
#define CR 13         // <ENTER> key

int main()
{
    int userEntry;
    do
    {
        printf("Press any key:  ");
        userEntry = _getche();

        printf("\nYou hit: ");
        if (userEntry == CR) printf("<ENTER>\n");
        else printf("%c\n", (char) userEntry);
        printf("ASCII code: %d\n", userEntry);

    } while (userEntry != CR);
}
BTW, the ASCII code for the Enter key is 13 (Carriage Return). On Windows machines, when you press <Enter>, the OS inserts two characters -- CR and LF (carriage return and line feed, ASCII codes 13 and 10, respectively). On Linux and Macs (I believe), only one of these is inserted, but I don't recall which one it is.
Win uses CR and LF, while *n*x uses LF only, and assumes CR.
 
  • #310
yungman said:
I was looking at the message after compile, I don't see where the demofile.txt saved.
View attachment 267210

The only thing I see in the program is the change of color as shown. It should all be RED, but the '\a' looks different. I googled, \a is alarm or alert. But alanr is the path in my computer, not much I can do.
View attachment 267211

thanks
Your string for the filename is broken. You have two options:
1) Escape the backslashes: Since the \ has a special "escape" meaning to toggle special characters in a string (e.g. \n for a newline character) you need to have some encoding for a backslash. The encoding is \\\\ . So your filename string would be "C:\\\\Users\\\\alanr\\\\Desktop\\\\ ...". That's the ugly but for some weird reason the arguably more popular solution.
2) Use forward slashes for paths. Windows understands them perfectly, and everything else uses them anyways (see the address field of your browser). Your filename string then becomes "C:/Users/alanr/Desktop/...".

Edit: Fun fact: This forum uses a similar escape mechanism for backslashes. So I had to edit my post and write \\\\\\\\ to get \\\\ show up in my post.
 
Last edited:
  • #311
Timo said:
1) Escape the backslashes: Since the \ has a special "escape" meaning to toggle special characters in a string (e.g. \n for a newline character) you need to have some encoding for a backslash. The encoding is \\ . So your filename string would be "C:\\Users\\alanr\\Desktop\\ ...". That's the ugly but for some weird reason the arguably more popular solution.
2) Use forward slashes for paths. Windows understands them perfectly, and everything else uses them anyways (see the address field of your browser). Your filename string then becomes "C:/Users/alanr/Desktop/...".
Already stated in post #303.
 
  • #312
Sorry I did not respond on the suggestions, I am hot on the trod trying to cover the things I missed now that I got a really good book, the Gaddis books is really good particular chapter 3 contains a lot of things I need and the first book just doesn't explain. I went through chapter 1 to 3 and finishing up chapter 4 today on conditional if then else, switch . I have not started on chapter 5 and beyond, I just copy some of the stuffs from the notes on the first book. I hope to breeze through chapter 5 as it's on loops. Chapter 4 and 5 are easy, I am looking forward to chapter 6 on FUNCTIONS, calling a function and all. I am excited getting into the modular programming.

I am sure I'll be back here with questions soon, but for now I just want to bull through the stuffs I learned from the first book and complete the holes not covered.

Thanks
 

Attachments

  • #313
Mark44 said:
Already stated in post #303.
:oldbiggrin:. I actually introduced a bug into our software yesterday that was totally avoidable if I had read the comment around line 4000 (of 27k) in the file I was editing.
 
  • Like
Likes Mark44
  • #314
I don't get the feel with this:

I have a question about setw() and setprecision() for cin. I know for character string, I can setw to limit the maximum character it will read in eg.
cin >> setw(4) >> input; If I type in "Alan", input only store "Ala" and '\n'.

How about numbers? say cin >> setw(2) >> number; I don't see there is a limit, I can put 12345, it will take the whole 12345.

1) My question is whether cin >> setw() work on numbers? How do I limit say number <=1000? Is there even a way? I tried setprecision(), it won't do it.

2) Is setw() more for lining up the numbers to the right on display? eg.
cout << "(" << setw(6) << number << ")"; will give (____12) if number = 12.(I have to use____for empty space).

This is the test program I am playing with
C++:
// setw() setprecision() and fixed do while
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

    double doubleValue = 91.0;
    cout << "Enter a double number   "; cin >> setw(2)>> doubleValue; cout << endl; cout << endl;
    cout << "(" << setw(6)<< setprecision(4) << doubleValue << ")" << endl; cout << endl;
    return 0;
}

Thanks
 
  • #315
yungman said:
1) My question is whether cin >> setw() work on numbers? How do I limit say number <=1000? Is there even a way? I tried setprecision(), it won't do it.
Although the setw() and setprecision() manipulators work with both output streams and input streams, they are most often used to format output streams. This VS documentation -- https://docs.microsoft.com/en-us/cpp/standard-library/input-stream-manipulators?view=vs-2019 -- (with emphasis added) says this.
Many manipulators, such as setprecision, are defined for the ios class and thus apply to input streams. Few manipulators, however, actually affect input stream objects. Of those that do, the most important are the radix manipulators, dec, oct, and hex, which determine the conversion base used with numbers from the input stream.
yungman said:
2) Is setw() more for lining up the numbers to the right on display? eg.
cout << "(" << setw(6) << number << ")"; will give (____12) if number = 12.(I have to use____for empty space).
setw() specifies the width of the display field for the next element in the stream. The ios_base class has flags that can be used to left-justify the thing being displayed, or right-justify it, convert lowercase characters to uppercase, display the thing in decimal, hex, or octal, and some others
 
  • Like
Likes yungman
  • #316
yungman said:
How do I limit say number <=1000?
You can't do that with the input statement alone. Consider that it would also need to have some way to specify what you want to happen if the number is > 1000.

You need to read whatever the user enters, then test it yourself. If it doesn't meet your condition, do whatever you think is appropriate. For example, if you want to display an error message and ask the user to try again:

C:
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main ()
{
    int inputNum;
    cout << "Enter a number <= 1000: ";
    cin >> inputNum;
    while (inputNum > 1000)
    {
        cout << "Hey dummy, I said <= 1000! Try again: ";
        cin >> inputNum;
    }
    cout << "OK, you entered " << inputNum << "." << endl;
    return 0;
}
 
  • Like
Likes pbuk and yungman
  • #317
Hi, I have been playing with setw() both in cout or cin, also fixed and setprecision(). I can see there's a lot of limitations, mainly use in cin is very limited. Even cin >> setw(5) doesn't work well at all. Here is my program

C++:
// setw() setprecision() and fixed do while
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

    double doubleValue = 91.0, copydouble = 100;
    char arr[20] = " This is a test", sentence[20];
    cout << "Enter a double number   "; cin >> doubleValue; cout << endl; cout << endl;
    copydouble = doubleValue;
    cout << "setprecision(4)          ("  << setprecision(4) << doubleValue << ")" << endl; cout << endl;

    cout << "setw(8) setprecision(4)   (" << setw(8)<< setprecision(4) << doubleValue << ")" << endl; cout << endl;

    cout << "setprecision(6)           ("<< setprecision(6) << doubleValue << ")" << endl; cout << endl;//Show setw(8) work only once.

    cout << "                          (" << copydouble << ")" << endl; cout << endl;// show setprecision(6) in effect for another double variable.

    cout << setprecision(2) << fixed;
    cout << "setprecision(2) << fixed  (" << copydouble << ")" << endl; cout << endl;

    cout << "nothing              ("  << arr << ")" << endl;
    cout << "setw(25)          (" << setw(25) << arr << ")" << endl; cout << endl;// showing setw() make it right justify.
    cout << "setw(4)                 (" << setw(4) << arr << ")" << endl; cout << endl;
   
    cout << "Enter characters:        ";  cin >> setw(5) >> sentence;
    cout << "You entered:  " << sentence << endl; cout << endl;//

    cout << "Enter characters:         ";  cin >> setw(5) >> arr;// This show if you enter over 10 consecutive character in sentense, it won't work.
    cout << "You entered:       " << arr << endl; cout << endl;
    return 0;
}

Particular printing characters.
1) cin >> setw(10)>> doesn't work for sentence, like you set to (10), if you type "This is a test", it only read in "This", soon as you have a space, it stop read.
2) The worst is if you try to read another array cin >> setw(10), it will read "is" from the last cin above. Meaning it will NOT clear the buffer inside after the first read. I tried the second read on array arr or array sentence. It will fail. You can play with the program.

Have to find a way to clear the buffer.

cin >> setw() simply does NOT work for numbers.
 
  • #318
This is not covered in the book, I want to write the length and width of rectangles to "dimension.txt" in the given directory. I can create the file, I can write to the file. Problem is I cannot separate the numbers, they all became one continuous numbers.

I want to .txt to look like
L1 W1
L2 W2

I experimented by adding " " for space and endl to go to the next line as shown in line 10 and 11 of the program. I got the way I want it. I want to verify this is the right way to do it as it's not in the book.
C++:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ofstream    outFile;
    int length, width, area;
    outFile.open("C:\\Users\\alanr\\Desktop\\C++ exercise\\Gaddis\\inout files\\dimensons.txt");
    cout << "Enter the length1 =  "; cin >> length; outFile << length << " ";
    cout << "Enter the width1 =  "; cin >> width; outFile << width << endl;
    cout << endl; cout << endl;

    cout << "Enter the length2 =  "; cin >> length; outFile << length << " ";
    cout << "Enter the width2 =  "; cin >> width; outFile << width << endl;
    cout << endl; cout << endl;
    outFile.close();

    return 0;
}

Thanks
EDIT: I played with this more, ofstream type is very much like std::cout. I can put "Length = " type of character strings to the file just like cout << "Length=" << length << endl; The book just doesn't talk about it.

I even use setw(), setprecision() and fixed. They are worked with ofstream!

I just want to check with you guys that all these are correct. I get used to electronics, just because it works doesn't mean a thing, you just don't do by trial and error.
 
Last edited:
  • #319
yungman said:
I can write to the file. Problem is I cannot separate the numbers, they all became one continuous numbers.

I want to .txt to look like
L1 W1
L2 W2

I experimented by adding " " for space and endl to go to the next line as shown in line 10 and 11 of the program. I got the way I want it. I want to verify this is the right way to do it as it's not in the book.
That's one way. You can also use setw(). It adds blank spaces before the number as necessary to produce the specified number of characters. This is better if you want to produce a table where the numbers in a column line up vertically (on the right side) even if they have different sizes (e.g. 1123, 45, 7, 230).

If the numbers are floats or doubles, and you also want the decimal points to line up, you can use setprecision().
 
  • Like
Likes yungman
  • #320
yungman said:
EDIT: I played with this more, ofstream type is very much like std::cout. I can put "Length = " type of character strings to the file just like cout << "Length=" << length << endl; The book just doesn't talk about it.
std::cout is a special case of an output stream, just as std::cin is a special case of an input stream. A difference between them and other input or output streams is that they are opened by default; you don't have to open or close them in your program.
Two other streams that are opened automatically are std::cerr and std::clog, which are used for errors and logging.
 
  • #321
If you already have experience in programming then I would recommend you to learn Python and Flutter as these are becoming really popular nowadays. I found this information on Facebook and it is really helping me out.
 
  • #322
jtbell said:
That's one way. You can also use setw(). It adds blank spaces before the number as necessary to produce the specified number of characters. This is better if you want to produce a table where the numbers in a column line up vertically (on the right side) even if they have different sizes (e.g. 1123, 45, 7, 230).

If the numbers are floats or doubles, and you also want the decimal points to line up, you can use setprecision().
Thanks, this is a light bulb moment, I was thinking also, yes, I can do it my way, but how am I going to line up different number in the future.

While I was waiting to confirm, I did the ifstream and ofstream with characters also like first name, last name. I think setw() will work also to line up. I'll try that later. This is starting to be fun!
I tried setprecision(2) << fixed to set the double number to 2 decimals using ofstream also, it works.

One good book really make a difference. My grandson use the Gaddis 8th edition, he gave me the answers for the question in the book, I actually bought a used 8th edition for $24. My C++ book are stacking up! The lost book magically appeared on my front porch. Now I have two copies and I am not even using that book!

Thank you and others for all the help.
 
Last edited:
  • #323
Mark44 said:
std::cout is a special case of an output stream, just as std::cin is a special case of an input stream. A difference between them and other input or output streams is that they are opened by default; you don't have to open or close them in your program.
Two other streams that are opened automatically are std::cerr and std::clog, which are used for errors and logging.
Yes, I forgot to mention that, in ifstream and ofstream type, I have to open and close them in the program.

I yet to find ways not to manipulate data better, how to NOT erase the old data if I choose to and add new data to the end of the stream, how to choose to read data instead of starting from the first piece every time. But I hope the book will cover it later. I am doing a lot more that the current chapters in the book already.

Thanks for all your help and patience.

Alan
 
  • #324
jtbell said:
If the numbers are floats or doubles, and you also want the decimal points to line up, you can use setprecision().
While playing around with this to refresh my memory (it's been several years since I last taught this stuff), I remembered that in order to get std::setprecision() to work, you also need to use std::fixed for fixed-point notation (e.g. 254.89) or std::scientific for scientific (exponential) notation (e.g. 2.55e+02).

The textbook I used long ago covered these details. I don't know if Gaddis does.
 
  • Like
Likes yungman
  • #325
jtbell said:
While playing around with this to refresh my memory (it's been several years since I last taught this stuff), I remembered that in order to get std::setprecision() to work, you also need to use std::fixed for fixed-point notation (e.g. 254.89) or std::scientific for scientific (exponential) notation (e.g. 2.55e+02).

The textbook I used long ago covered these details. I don't know if Gaddis does.
Yes, I notice that, the setprecision() is not too useful other than that. I experimented quite a bit.
 
  • #326
yungman said:
I yet to find ways not to manipulate data better, how to NOT erase the old data if I choose to and add new data to the end of the stream
To do this, you need to open the file in append mode. Here's an example that I modified from the VS documentation (ios_base class, https://docs.microsoft.com/en-us/cpp/standard-library/ios-base-class?view=vs-2019#ios_base):
C++:
// ios_base_openmode.cpp
#include <iostream>
#include <fstream>
using std::fstream;
using std::ios_base;
int main()
{
    fstream file;
    file.open("rm.txt", ios_base::app);
    file << "testing\n";
}
Here I'm opening the file in append mode, which implies that the file is an output file. There are several other flag values, including in, out, trunc, ate, and binary.
yungman said:
how to choose to read data instead of starting from the first piece every time.
If you want to open a file for reading, but want to start somewhere other than the beginning of the file, you need to move the position-in-file pointer to where you want it, and then start reading from there. To do this, you can use basic_istream::seekg(). There's a so-so example here -- https://docs.microsoft.com/en-us/cpp/standard-library/basic-istream-class?view=vs-2019#seekg. There is another example here: http://cplusplus.com/reference/istream/basic_istream/seekg/.
 
  • Like
Likes yungman
  • #327
Mark44 said:
To do this, you need to open the file in append mode. Here's an example that I modified from the VS documentation (ios_base class, https://docs.microsoft.com/en-us/cpp/standard-library/ios-base-class?view=vs-2019#ios_base):
C++:
// ios_base_openmode.cpp
#include <iostream>
#include <fstream>
using std::fstream;
using std::ios_base;
int main()
{
    fstream file;
    file.open("rm.txt", ios_base::app);
    file << "testing\n";
}
Here I'm opening the file in append mode, which implies that the file is an output file. There are several other flag values, including in, out, trunc, ate, and binary.
If you want to open a file for reading, but want to start somewhere other than the beginning of the file, you need to move the position-in-file pointer to where you want it, and then start reading from there. To do this, you can use basic_istream::seekg(). There's a so-so example here -- https://docs.microsoft.com/en-us/cpp/standard-library/basic-istream-class?view=vs-2019#seekg. There is another example here: http://cplusplus.com/reference/istream/basic_istream/seekg/.
Thanks, I'll try this later.
 
  • #328
This is the program I wrote that is away from the examples in the book that are very simple. I actually drew the flow chart first to write the code. I attached the flow chart.

The program is to keep temperature of oven between 101deg C to 103deg C. It check the temperature, if it is too low, turn up the over, wait for 5 mins and recheck, repeat until the temperature is equal or higher than 101deg C. If temperature is too high, turn down the over and wait for 5 minutes and read the temperature again, repeat until temperature is below or equal to 103deg C. If the temperature is within range, check every 15 minutes. The program will ask whether you want to quite, if not, it will keep checking. This involve switch-case and do-while.

C++:
//this program check temp, if 101 <=temp<=103deg C, check every 15mins.
//If it's over, turn it down, check every 5 minutes until correct temp.
#include <iostream>
using namespace std;

int main()
{
    int temp = 100;
    char userSelection = 'A';
    char caseSelect = 'C';
    const char ENT = '\n';
  
    do
    {
        cout << "What is the temperature?   ";
        cin >> temp; cout << endl; cout << endl;//Read temperature.

        if (temp < 101) caseSelect = 'A';//Temperature too low.
        else if (temp > 103) caseSelect = 'B';//Temperature to high.
        else caseSelect = 'C';// Temperature in range.

        switch (caseSelect)
        {
        case ('A'):// Temperature too low.
            {while (temp<101)
                {
                cout << "Raise the temperature, wait 5 minutes and measure again.\n\n";
                cout << "Read temperature.  "; cin >> temp;
                }
            }
      
        case ('B')://Temperature too high
            {while (temp>103)
                {
                cout << "Lower the temperature, wait 5 minutes and measure again.\n\n";
                cout << "Read temperature.  "; cin >> temp;
                }
            }
      
        case('C')://Temperature in range.
            {
            cout << "Wait 15 minutes and measure again.\n\n";
            }
          
            cout << "Hit ENTER if you want to quit, hit any other key to continue.\n\n";
            cin.ignore(255, '\n');// Clear '\n' from last ENTER.
            cin.get(userSelection); cout << endl; cout << endl;//Read whether to quit.
        }
    } while (userSelection != ENT);
    cout << "you chose to quit, goodbye.\n\n";
    return 0;
}

It is working, I don't have any question. Just want to show my first program I wrote. Thanks for all the help so far.
 

Attachments

  • #329
Just curious... why did you do it in two steps via the caseselect variable? Simply to get some practice with the switch statement?
 
  • Like
Likes yungman
  • #330
jtbell said:
Just curious... why did you do it in two steps via the caseselect variable? Simply to get some practice with the switch statement?
Thanks for taking the time to look at it.

This is not a practice on switch-case, I actually want to write a more complicate program than what the book shows. It's not even started out using switch-case. I want the program to be as simple and straight forward on the flow. I believe my design is the simplest, no crossover from one path to the other, the flow going straight down.

Also, I take care of what to me the most important thing, that is to take care of under damp situation like if the temperature is too high, I lower the heat, it can get too low under 101degC, I want a way to recover that by raising the oven temperature. This program will do that so it will make sure it will get to the temperature range between 101 and 103deg C.

Yes, I found out after design the program, that switch-case doesn't take conditional statement. That is switch can only take simple case of A, B, C, D etc. It will not read

switch ( temp)
case ( temp <101):
case (temp >103):

I have no choice but to use if-else if - else to put A, B and C for the case statement.

This program is really like the kindergarten version of closed loop feedback temperature control. I can see in the future, I can add in time constant and oven control. Like if the temperature is over 10deg below the optimal range, I would turn the oven full blast until it's within say 5deg. Then I back off the oven and check more frequently. Then if it is within 2deg, I back off even more to let the temperature ease into the optimal range.

thanks
 
Last edited:

Similar threads

  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 107 ·
4
Replies
107
Views
9K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
16
Views
3K
  • · Replies 54 ·
2
Replies
54
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 58 ·
2
Replies
58
Views
4K