Jump to content

357mag

Members
  • Content Count

    104
  • Joined

  • Last visited

Everything posted by 357mag

  1. Cool program which I like using a global variable. But the compiler says reference to count is ambiguous. It is one of Herb's programs, and I know his style of writing program is suspect, but his programs themselves as far as his ideas I have always liked. Here it is: #include<iostream> using namespace std; void functionOne(); void functionTwo(); int count; int main() { int i; for(i = 0; i < 10; i++) { count = i * 2; // reference to count is ambiguous functionOne(); } system("pause"); return 0; } void functionOne() { cout << "count: " << count; cout << endl; functionTwo(); } void functionTwo() { int count; for(count = 0; count < 3; count++) cout << '.'; }
  2. 357mag

    Pointer arithmetic question

    I'm trying to understand some basic pointer arithmetic. I guess when a pointer is incremented (like ptr++) it does not get incremented by 1. Instead the address increases by 1 multiplied by the size of the data type it is pointing to. If ptr initially held an address called 2000, then ptr++ would make it point to address 2004. What I don't understand is I read "each time ptr gets incremented, it will point to the next integer." What does that mean? The next integer? What next integer?
  3. 357mag

    Pointer arithmetic question

    Excuse me sir for asking a question. Jump in a lake.
  4. I want to print a line of text using cout but there is a word that I want to have quotation marks around it. I want the output to look like this: Looking for the index position of the word "own". What I've tried so far has not worked. Here is what I got currently: int main() { string sentence = "To thine own self be true"; string word = "own"; cout << "The sentence is: " << sentence << endl; cout << "Looking for the index position of the word \"own\"; cout << sentence.find(word) << endl; system("pause"); return 0; }
  5. 357mag

    How to get the quotation marks to show

    Okay I got it going now.
  6. I'm considering working in Delphi for awhile, and I was looking through my books (I have four of them), and every book starts off right away with Windows programming. None of the books teaches you console programming. Personally, I like console programming. I was wondering if there is a reason all of my books starts you off that way. Perhaps because Delphi is a clean, fairly easy to grasp language?
  7. 357mag

    Program works fine but why?

    Just one question about the way this program is working. I make a constant and initialize it to 10. I use that to make the size of the array called name1. What I don't understand though is if I run the program and enter in a long name that is longer than 10 characters, C++ still allows me to do it and the program works just fine. I was expecting an error message saying something about 'out of bounds error". I don't get why C++ is allowing me to enter in a name that is longer than the size of the array: #include<iostream> #include<cstring> using namespace std; int main() { const int SIZE = 10; char name1[SIZE]; char name2[SIZE] = "C++owboy"; cout << "Howdy! I'm " << name2 << "!"; cout << " What's your name?" << endl; cin >> name1; cout << "Well, " << name1 << " your name has "; cout << strlen(name1) << " letters" << endl; cout << "Your initial is " << name1[0] << endl; name2[3] = '\0'; cout << "Here are the first three characters of my name: "; cout << name2 << endl << endl; system("pause"); return 0;
  8. I've never used range-based for loops so I don't know how to write one that is keeping track of the sum of the elements in an array: int main() { int myArray[] = {2, 4, 7, 8, 9}; cout << "The values in the array are: "; for(int n : myArray) cout << n << " "; int sum = 0; for(int x : myArray) { x += myArray[x]; // don't know what to write here } cout << "The sum is: " << x << endl; // use of undeclared identifier system("pause"); return 0; }
  9. Yes that works great. Thank You.
  10. Something is still off. My console window is saying that sum is equal to 1985788.
  11. I'm looking around the IDE for something that will allow me to add a header file to my project. Do I right-click on the project and just select Add Unit? I also need to add a .cpp file too.
  12. 357mag

    How do I add a header file to my project?

    Oh I believe I found it. Anyway I made my first project that uses a header file to hold the function prototype, and a .cpp file that holds the implementation. The int main( ) file I named Odd Or Even.cpp (The program determines whether two numbers are odd or even). The header file I added to the program it holds the function prototype I named it MyLib.h The additional .cpp file I added that holds the implementation I named it MyLib.cpp I'm not too clear on the last file which C++ Builder generates when you create a new project. C++ Builder calls it PCH1.h. Here it is: #ifdef _WIN32 #include <tchar.h> #endif bool isEven(int number); But it seems like I have two function prototypes going on. One here in this PCH1.h file, and the other one in the MyLib.h file. I had to place the function prototype here because the compiler complained about an undeclared identifier without it. Then I commented out the prototype in the MyLib.h file and rebuilt the project and it ran fine so I deleted that file. But what is this PCH1.h file about with this code that automatically comes with it? PCH stands for what?
  13. Here is one of my projects which was written in an earlier version of C++ Builder. You will notice that I'm using #include<conio.h> plus I'm using getch(); // This program demonstrates writing a simple function to cube a number #include <iostream> #include <conio.h> using namespace std; int cube(int y); // function prototype int main() { int x; cout << "Enter an integer value: "; cin >> x; int answer = cube(x); // call the cube function and pass x as an argument and assign result to the variable answer cout << "That number cubed is " << answer << endl; // print the result getch(); return 0; } int cube(int y) // function definition { return y * y * y; }
  14. 357mag

    Earlier version of C++ Builder program

    Someone asked to see the code. So I post the code.
  15. 357mag

    This is a change

    In previous versions of C++ Builder, I remember having to use the include<conio.h> header file. Plus to keep the console window open I had to put getch() at the end of my source file. Now I just copied a .cpp file which was made in Visual Studio, and I pasted it into a source file in C++ Builder. I didn't think it would run, but it did with no complaints from the compiler. I did not include the <conio.h> file nor did I have to place a getch() at the end. C++ builder simply ran the file just fine. Did Embarcadero change some things? I'm using the Community Edition 12.
  16. 357mag

    This is a change

    There is no code that behaves differently.
  17. I'm working on a program using Logical Operators, and everything is working fine, except for one line that the compiler says it's incompatible types. It's a bit messy to look at also, but it works. And is there a way to tell Delphi to print the words true and false instead of the integer values -1 and 0? The line that is not correct yet is the fifth line down (the MemoResult lines) the one where I'm using the not operator. I don't know how best to write it. Here is my code: procedure TFormLogicalOperators.ButtonOKClick(Sender: TObject); var a: boolean; b: boolean; begin a := true; b := false; MemoResult.Text := ('a: ' + BoolToStr(a)) + sLineBreak; MemoResult.Text := MemoResult.Text + ('b: ' + BoolToStr(b)) + sLineBreak; MemoResult.Text := MemoResult.Text + ('a and b: ' + BoolToStr(a and b)) + sLineBreak; MemoResult.Text := MemoResult.Text + ('a or b: ' + BoolToStr(a or b)) + sLineBreak; MemoResult.Text := MemoResult.Text + ('not a: ' + BoolToStr(not (a + b))) + sLineBreak;
  18. 357mag

    One line of code not quite right

    Where do you place the function header? Calling a function that is already defined somewhere is one thing. Declaring or defining it is another. I may have to come back to this program later on.
  19. 357mag

    One line of code not quite right

    You are way ahead of me. I have not studied functions or procedures yet. Can you write out the code?
  20. 357mag

    One line of code not quite right

    Oh...I fixed it. It's working now.
  21. I have a program and there is a Edit box and a few buttons. When the program is run, I want to be able to press a button called Show Values and then you will see two lines of code: The value of x is: 6, and The value of y is 7. But I want each line to print on a new line. So I put an sLineBreak in there but it's not working. The second line is just printing after the first line. It should look like this: The value of x is 6 The value of y is 7 Here is my code so far: procedure TFormIncrementAndDecrement.ButtonShowValuesClick(Sender: TObject); var x, y: integer; begin x := 6; y := 7; EditResult.Text := 'The value of x is: ' + IntToStr(x) + sLineBreak; EditResult.Text := EditResult.Text + 'The value of y is: ' + IntToStr(y);
  22. 357mag

    My sLineBreak is not working

    I got it working now. I forgot to include sLineBreak.
  23. 357mag

    My sLineBreak is not working

    It still is printing on the same line.
  24. 357mag

    My sLineBreak is not working

    Thank You, that is working much better. But when I run my program the words MemoResult show in the Memo control. How do I get rid of them? I've looked in the Object Inspector and I don't see a way to remove them from the Memo contol.
  25. Is there a page out there somewhere that shows some naming conventions for the controls in C++ Builder? Like how do you abbreviate things like the Edit box or the Label etc? Do you just follow Visual Studio conventions? Just wondering what would be some good naming abbreviations.
×