Trying to decide which programming language I want to learn

In summary: C++ is considered a lower-level language, meaning that it is closer to the hardware and gives you more control over how your program runs. However, C# is a high-level language, which means it is easier to learn and use and has a lot of built-in libraries that make coding faster and more efficient. Both languages have their advantages and disadvantages, and it ultimately depends on what type of project you are working on. For gaming, C++ is often preferred because of its speed and control, but C# has become increasingly popular in game development as well. It's worth trying both and seeing which one you prefer working with.
  • #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
Technology news on Phys.org
  • #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

  • Program to keep temperature of oven between 101deg C to 103deg C.docx
    188.3 KB · Views: 111
  • #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:
  • #331
yungman said:
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.
You can make the program a lot simpler by eliminating the switch statement. Also, it simplifies things greatly if you don't confuse the user by asking for numeric and character input (i.e., asking for a temperature followed by the Enter character to quit).

Here's my simplified version.
C++:
// Program checks temperature.
// If 101 <= temp <= 103deg C, check every 15mins.
// If temp > 103 C, turn heat down, check every 5 minutes until correct temp.
// If temp < 101 C, turn heat up, check every 5 minutes until correct temp.
#include <iostream>

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

int main()
{
    int temp;

    do
    {
        cout << "Enter the temperature, or a negative number to quit.   ";
        cin >> temp;            // Read temperature.
        if (temp < 0) break;    // If negative, exit do loop.
       
        if (temp < 101)
        {
            // Temperature too low.
            cout << "Raise the temperature, wait 5 minutes and measure again.\n\n";
            continue;

        }
        else if (temp > 103)
        {
            // Temperature too high.
            cout << "Lower the temperature, wait 5 minutes and measure again.\n\n";
            continue;
        }
        else
        {
            // Temperature is between 101 and 103 degrees C.
            cout << "Wait 15 minutes and measure again.\n\n";
            continue;
        }               

    } while (true);
    cout << "You chose to quit, goodbye.";
}
The do ... while loop is an infinite loop that uses continue to start a new loop iteration, and break to get completely out of the loop.

Input from the user is asked for once, at the top of the loop. The user can enter any integer value 0 or larger, or can enter any negative number to exit the program.
 
  • Like
Likes yungman
  • #332
Mark44 said:
You can make the program a lot simpler by eliminating the switch statement. Also, it simplifies things greatly if you don't confuse the user by asking for numeric and character input (i.e., asking for a temperature followed by the Enter character to quit).

Here's my simplified version.
C++:
// Program checks temperature.
// If 101 <= temp <= 103deg C, check every 15mins.
// If temp > 103 C, turn heat down, check every 5 minutes until correct temp.
// If temp < 101 C, turn heat up, check every 5 minutes until correct temp.
#include <iostream>

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

int main()
{
    int temp;

    do
    {
        cout << "Enter the temperature, or a negative number to quit.   ";
        cin >> temp;            // Read temperature.
        if (temp < 0) break;    // If negative, exit do loop.
    
        if (temp < 101)
        {
            // Temperature too low.
            cout << "Raise the temperature, wait 5 minutes and measure again.\n\n";
            continue;

        }
        else if (temp > 103)
        {
            // Temperature too high.
            cout << "Lower the temperature, wait 5 minutes and measure again.\n\n";
            continue;
        }
        else
        {
            // Temperature is between 101 and 103 degrees C.
            cout << "Wait 15 minutes and measure again.\n\n";
            continue;
        }            

    } while (true);
    cout << "You chose to quit, goodbye.";
}
The do ... while loop is an infinite loop that uses continue to start a new loop iteration, and break to get completely out of the loop.

Input from the user is asked for once, at the top of the loop. The user can enter any integer value 0 or larger, or can enter any negative number to exit the program.
Thanks for taking the time. I did started out with flowing through concept like what you have. But my goal is to continuous monitoring. It became messy doing it this way.

Like I explain before, my program is like a kindergarten version of closed loop feedback temperature control, not just doing one adjustment and it's done. The way I loop is to monitor over and under shoot of temperature and adjust so it will settle into the optimal range. I can envision in the future, I can add time constant within the do-while that nested under the switch-case to control the oven, if the Temp is over 10deg below the lower limit, crank the oven high, but when temp approach the lower limit, turn the oven down and ease into the optimal range. Then when it's in optimal range, keep it there by touching up the oven control every time it loops around.

I did this more in system point of view, I spent a few hours designing the flow chart, only like half an hour to code it.

I can't wait to get to chapter 6 functions and chapter 9 pointers.

Thanks for you time to look at it.
 
Last edited:
  • #333
I am studying chapter 6 Functions. I am confused, I read all along that C++ is an Object Oriented programming, that the program calls on Objects to perform a certain task. That an Object is a self contained unit the consists of it's data and codes to work on the data. That the program call on the Object with given parameters and the Object performs the task and return back the parameters.

But this is EXACTLY what Gaddis book described as Function! That the main() is a function, each of the Object ( subroutine) it calls is a Function. That the Headers the program used in #include <> contain all the Function needed.

What am I missing? This goes right back to my biggest road block in learning the C++ again. I have to say after writing quite a bit of programs by now, coding and even designing the program is the EASY part of C++. This kind of fancy naming is the difficult part and the most confusing part. I am so lucky I decided to order my grandson's book( Gaddis), or else I would be still be struggling.
 
  • #334
Again, I will say that I don't have Gaddis's book, so I am just guessing. Nevertheless, based on my experience with C++ textbooks many years ago, I will guess that he and you are still in the realm of procedural programming.

I will guess that a following chapter will introduce you to "structs", which are collections of data of different types, as opposed to arrays, which are collections of data of the same type.

Then, a later chapter will introduce you to "classes". They define objects that are basically structs that also include "member functions" that act on the data that the objects contain. Then you will enter the realm of object-oriented programming.
 
  • Like
Likes yungman
  • #335
Gaddis gets to objects and structures in the next chapter. He is working you thru procedural programming then he eases you into object oriented. The best layman's description I can give is that a function can return one thing only, i.e., a matrix, a float etc...whereas a structure with it's defined functions, can return a collection of things.

I remember when I was taking the course, we had to write a program to calculate trhe propertiesd of a rectangle, the area and perimeter. Both take the exact same arguments and I remember saying that if I could return two things from this function, I'd only have to write one function. Whohooo when I learned about structures and classes...
 
  • Like
Likes jtbell and yungman
  • #336
Dr Transport said:
Gaddis gets to objects and structures in the next chapter. He is working you thru procedural programming then he eases you into object oriented. The best layman's description I can give is that a function can return one thing only, i.e., a matrix, a float etc...whereas a structure with it's defined functions, can return a collection of things.

I remember when I was taking the course, we had to write a program to calculate trhe propertiesd of a rectangle, the area and perimeter. Both take the exact same arguments and I remember saying that if I could return two things from this function, I'd only have to write one function. Whohooo when I learned about structures and classes...
I guess I am too impatience! I'll wait till I get there.

thanks
 
  • Like
Likes Dr Transport
  • #337
I am back to my question of my original title of this thread. I am going to finish this C++ following the college class. I want to look ahead to what's next to plan ahead. I picked C++ first as it's the closest to my trade, hardware application where C++ is closest to the real hardware and the fastest.

1) What language Windows use in their programs? Like if I want to understand windows, what language should I learn next or what stuff should I learn? I have a suspicion it's NOT C++.

2) What language is most common for web design?

3) What language is most common for writing games?

Thanks
 
  • #338
yungman said:
2) What language is most common for web design?
Do you mean "web design" as in the graphic design and layout of the page or are you using the term to me "web delvelopment" that is the creation of websites and web based apps.

In terms of web design, it is mostly HTML and CSS, both of which are pretty simple and straight forward. To some extent Javascript (JS). But the use of JS begins to blur the line between design and development.

In terms of web development, you must also make the distinction between server side and client side. For the server side, the most common language is most likely PHP. Client side it is by far JS as it is native to every available browser. Other languages would require some kind of client download.

Personally I don't like PHP, I much prefer Python, you can use frameworks such as Flask, Django or multitude of others. Then you can use the same language to other non-web related things. And, you can then integrate your non-web things with the web and not require any other languages.

Client side, I like to stick with plain Javascript, but you can use other frameworks such as React, Angular, or JQuery and then also use JS server side with NodeJS.
 
  • Like
Likes sysprog and yungman
  • #339
I was searching on google, it said Windows Kernals are written in C, C++ or C#. Does that mean the Windows is written in C related language, that I am learning the right language?
 
  • #340
yungman said:
I was searching on google, it said Windows Kernals are written in C, C++ or C#. Does that mean the Windows is written in C related language, that I am learning the right language?

Unless you are planning on writing Windows kernel code, or a Windows driver for some piece of hardware, you don't have to write Windows programs in the same language as the Windows operating system is written in.

AFAIK the language Microsoft currently seems to be pushing for people to write Windows programs in is F#, which is a sort of successor to C#. I personally don't have any need or desire to use anything Microsoft is pushing; when I need to write code to run on Windows, I write it in Python.
 
  • Like
Likes sysprog
  • #341
PeterDonis said:
Unless you are planning on writing Windows kernel code, or a Windows driver for some piece of hardware, you don't have to write Windows programs in the same language as the Windows operating system is written in.

The language Microsoft currently seems to be pushing for people to write Windows programs in is F#.
Thanks for the reply, I am more interested in understanding windows, I thought knowing that language allows me to read some of their codes to understand it better. Understand how the kernels and drivers work is good too.
 
  • #342
yungman said:
Thanks for the reply, I am more interested in understanding windows, I thought knowing that language allows me to read some of their codes to understand it better. Understand how the kernels and drivers work is good too.
Windows is mostly supplied as object code only (non-source), although various versions of various pieces of it have been leaked. MS has provided a lot of other material for open source distribution. MS recently released source code for Windows Calculator
https://github.com/Microsoft/calculator
and for Windows File Manager
https://github.com/Microsoft/winfile/

For general understanding of inner workings of Windows, you might check out Inside OS/2 (1988), by Gordon Letwin.
 
Last edited:
  • Like
Likes yungman
  • #343
Thanks for the reply, sounds like people can use any program to write to interface with Windows. I kept thinking you have to match the language of the program written in order to interface and work with the existing program. I guess you don't have to, you just need to know the interface.

Is it generally true that you can use C++ to interface with any other language? Is there a standard of interfacing that people follow?

If that is all true, then there is NO need to learn different languages, you just need one and you can do everything! I understand that maybe it's more convenient using one language over another for certain situation, but it can be done using one language only. Is that true?

BTW, I am surprised I don't have question lately. With Gaddis, it's been smooth. Particular as I learn more, when I google, I found out they are not all written in Russia! Some actually written in English! At the beginning, when you guys kept saying google first, but when I did that, they all seemed to be written in Russian to me! Now it's getting better.

Thanks
 
  • #344
yungman said:
I kept thinking you have to match the language of the program written in order to interface and work with the existing program. I guess you don't have to, you just need to know the interface.

Windows is not a program, it's an operating system. All operating systems have interfaces that any program has to use, and all programming languages have library functions that know about the interfaces of all operating systems that those programming languages can run on.

Programs in general don't have interfaces; they aren't designed to have other programs work with them. They're just designed to do whatever it is they do.

yungman said:
Is it generally true that you can use C++ to interface with any other language?

No.

yungman said:
Is there a standard of interfacing that people follow?

No.

yungman said:
If that is all true, then there is NO need to learn different languages, you just need one and you can do everything! I understand that maybe it's more convenient using one language over another for certain situation, but it can be done using one language only. Is that true?

You can in principle write pretty much any program in any language. But many programs are much easier to write in some languages than in others.
 
  • Informative
Likes yungman
  • #345
PeterDonis said:
......
You can in principle write pretty much any program in any language. But many programs are much easier to write in some languages than in others.
What is the best language to interface with Windows?

What is the most popular language to write pc gaming?

Thanks
 
  • #346
I spoke too soon. I fail to compile this program. It's a very simple program but if failed. It is EXACTLY as in the book, I checked many times and I also understand what the program want and everything is correct.
C++:
//Default Arguments
#include <iostream>
using namespace std;

void displayStars(int = 10, int = 1);// Default argument to 10 and 1 in prototype.

int main()
{
    displayStars(); cout << endl;
    displayStars(5); cout << endl;
    displayStars(7,3); cout << endl;
    return 0;
}

void displayStars(int cols, int rows)
{
    for(int down = 0; down < rows; down++)
    {
        for (int across = 0; across < cols; across++)
        {
            cout << "*";
        }
        cout << endl;
    }
}

The error message is:
Compile error file write.jpg


Can anyone see what's happened? What does that mean of cannot open the file? It's opened, I am working on it!

Thanks
 
  • #347
Next time you get an error message, please try looking it up:

1597002465771.png

You can see from the explanation that the error has nothing to do with the program code.
 
  • #348
yungman said:
What is the best language to interface with Windows?

I don't think there is a single "best" language to interface with any operating system. All major languages know how to interface with all major operating systems.
 
  • Like
Likes sysprog
  • #349
sysprog said:
Next time you get an error message, please try looking it up:

View attachment 267544
You can see from the explanation that the error has nothing to do with the program code.
I read a few this before I posted, I don't understand why.

It is strange. I copy the .cpp out, created another project, put in the EXACT source.cpp. It ran on the new project under new name.

What went wrong, that's what I don't understand.

It's even more strange, I closed VS, I try to delete the whole program folder that has problem, I can't even delete it, it said the program is opened somewhere! I closed everything. The only other thing left is restart the computer!
 
  • #350
yungman said:
I read a few this before I posted, I don't understand why.

It is strange. I copy the .cpp out, created another project, put in the EXACT source.cpp. It ran on the new project under new name.

What went wrong, that's what I don't understand.
The message explanation refers to what amounts to a version control problem (can't find referenced file in this version) that is entirely unrelated to anything in the .cpp code.
 

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
8
Views
866
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
3K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
2
Replies
58
Views
3K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
Back
Top