WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It takes the initial balance and will let me input a credit or a debit but the part where it is supposed to display a new balance after each deposit is where I am getting some trouble.

Then you didn't program the thing right. You said you're "getting some trouble", but that's not a description of a problem. It's asking us to figure out what you already know but were too lazy to actually explain.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's not impossible. By C++ native I mean other headers it comes with when you download an IDE and NOT just the input and output stream. Don't tell me it's impossible and lie to me; it's not.

OK. You obviously know more than I do. I've only been programming for 30 years and must not know enough yet. And since I'm wrong, tell me how you can do it...

And I have not a clue on what I can do that's lesser than a snake game, but larger than any one input output program. Plus, how could I work my way up to a snake game if I don't even know where to start?

I'm not exactly following a road here.....

Then buy or download a book or follow a tutorial. You can't just do neurosurgery without learning how to use a scalpel first.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your formatting makes the code difficult to follow. Here's a writeup about formatting that will help you help us follow the code easier.

I can't really tell, but "however I still can't get the sentinel to work properly but everything else seems to be working properly" kinda sounds like you might be asking for help. If so, be specific and explain.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

5/9 = 0 so you are multiplying by 0.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am not just entering one character at a time. I'm entering a string of 8-11 characters into the array.

I never said anything about 1 character. I said 1 input. Your input is a c-string.

I am determining the size of the array to use later down the so I can count to it when outputting the array. I had a problem that if I entered a string like "four" It would print out FOUR then a bunch of garbage behind it. That seemed to fix that.

But if your string ends in '\0', outputting with cout will stop at the end of the string. Therefore, something else is wrong and you are probably changing the '\0' to something else. Go through your loop carefully to see if it ends properly.

To Be Honest, If i knew how to "Test each letter individually" to see if it was lowercase, and if it was, change it to upper case useing a string I would, however I'm barely grasping these concepts so I'm working with what I can.

Ahh, but you are testing each letter individually. That's exactly what your loop does.

I am recursively calling the input function to loop the program back to the input. I appreciate the suggestions and mull them over and see if I can rearrange my code to make it work.

Very bad programming to recurse just to start over. Starting over is best done with a loop.

Ok I cleaned …

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I have no idea at all, nothing, on how to make a full, running and working snake game.

Then you should probably do something you at least have an idea how to do. Do this project later when you're not so clueless.

... And I mean do it with out extended graphics, only C++'s native things, and it's possible

Actually, using native C++, this task is actually impossible. Native C++ has no way to control where to put stuff on the screen nor can it accept input asynchronously which is required for this project.

As I said, you may want to choose another project that you can do that uses native C++, something that you don't quite know how to do but you aren't completely clueless about.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Why are you entering a single input and calling the convert function on that single input?
2) In the convert function, why are you testing the array just to find the size, then going through an identical loop structure to test/convert each character? Use 1 loop.
3) In the convert function, why are you outputting each character in a loop? If the array is a c-string why not just output the string?
4) In the convert function, why are you recursively calling the input function? Wouldn't it be better to:

Start Loop
    Get Input
    Convert Input
    Output Converted String
End Loop

Let the getinput() function get the input, not do all the work.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

i am a junior programmer so dont be surprised by the simplicity of the code i am using
i have managed to write the code for the atm machine but i dont know why one case switch (case3 abd case 4),the complier has showed no error
please help
<as i said i'm a junior programmer>

and obviously the head of the Department of Redundancy Department, too...

As for the question, what kind of error would you like it to have? You have to program the one case statement :icon_rolleyes: with an error the compiler can't handle to get a compiler error.

Please proofread your posts before you submit them to be sure you have made accurate and understandable statements. If not, feel free to edit your post before submitting, or click the EDIT POST button after submitting to clean up any questionable information.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Change char det = *test; to char *det = test;

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How do I make this code use that equation? What would you suggest?

Since this is your very first post, you don't. You come with your own technique and write your own code, and don't hijack arguav74's thread. You don't steal someone else's code for your own homework.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

ok so here the problem the code works just adds break on to every line i want it to only add breaks to the line that don't alraedy have spaces after them.

OK so you say you have a problem then you say the code works and it just does something about break but you don't say what break means and what spaces have to do with anything the code you posted without code tags by the way you need to use them doesn't do anything with spaces nor breaks so we don't have any idea what you are really doing you might want to explain in detail what you are trying to do also explain what the code does wrong be explicit and also write in real english you know sentences punctuation and so on so we can understand what you are writing

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Same with
clubs
organizations
scheduled group dinners
AA Meetings

IOW, that's how life works... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

never heard of a forward key

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do the reverse of how you got the data into the file. fread() and fwrite() can be thought of as direct opposites.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Two things I see: for(jj=0; jj< (n-(1-j)); jj++) /* inner loop and compares adjenct items */ I don't believe jj< (n-(1-j)); is doing what you want. Try calculating values of jj using various values of j.


Are you assigning or comparing cnt in this IF statement?

if (cnt = MAXIMUM)
                printf("full-overflow\n");

Also, please use better formatting. Your indentation is very inconsistent making the program a little hard to follow.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I did this....simple but works

int main()
{
  char c1, c2;
  c1 = getchar(); // get first input
  c2 = getchar(); // get second input
  if (c1 == '\n' && c2 == '\n') // if post inputs are enter
     exit(1); // exit
}

So what happens if someone types in " [ENTER][ENTER]"?

Put each getchar() in a loop testing for '\n': while (getchar() != '\n');

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you are using fwrite() you should probably be using fread() , not fgets()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry Walt, I guess I don't really understand what you are asking.

Really... Then we need to teach a basic English concept.
Q1: What constitutes the beginning of a sentence? Rephrase: What is the definition of a sentence? How do you know when a sentence ends? How can you tell what the first character of a sentence is?
If you don't understand these questions, you can't really program the task.

the text file from the book to use for testing is this:

this is a TEST file.
the sentences in this file are of varying
lengths. some span lines.

others DO NOT.

How many sentences are there? What is the first letter of each sentence? How can you tell?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I tried using the seekp member function but could not figure out where it needed to go. It just made my output file all over the place.

This is what I tried to get the first letter in the sentence:

inFile.seekp(0L, ios::beg)

I'm just not sure where to put it. I had a lot of problems with loops in my past programing class.

Why? You don't need seekp() at all.

Try answering my questions. I asked them for a reason.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

C'mon, guys, think!

Any guesses what fscanf(fp, [B]"%d"[/B], &bInt); might do?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In response to 1), isn't that what I'm doing by saying denom += 2 and power +=2 on lines 32 and 37?

Well, technically, yes. But when you need denom to be 5 you calculate 1,3,5. Then when you need 15 you calculate 1,3,5,7,9,11,13,15. But if you need 15, wasn't the last calculation 13? So rather than calculating all those other values, why not just add 2? And since power is the identical value, why calculate it at all? You've already got the value in denom.

In response to 2), that is just what I put since I was basing it off of a program I have that calculates sin(x). I am just confused as to how to get it to work for arctan and then using that calculation to derive pi.

My question stands. You have the equation. Make your code use that equation. You can certainly base it off another program, but you still have to change it to the correct equation.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just for clarification, are you asking us to fix the code and give it to you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Other than minor formatting and C++ in the title (what forum is this?), your first post is quite good.

What constitutes the beginning of a sentence? How can your program recognize it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Why calculate the denom and power values from scratch each time? Just add 2 each time through the loop.

2) How does sign*power/denom; equate to x^5/5 ? Where's your x? Where's x^5?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If you enter ^v or backspace, you can display the integer value of the keys to find out what to compare the key value to.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And moved again to C++

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

-if i cant call main, how do i make it start from the top of main if they type incorrectly?(tried *main(); and &main(); also, if thats considered calling main i will not do it anymore)

Let's restate the problem... How do you loop back to the beginning of the program?

Try writing a test program to see how you can apply this hint. Get to the point you understand how that works (complete with the YES/NO question).

Then write another test program to try one more single task you need to accomplish. Now merge these two tests.

Continue in this manner.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It all boils down to what you need. str points to the first character of the string *str is the first character of the string str[n] is the nth character of the string *str and str[0] are functionally equivalent

str[2]---v
      str ==> FULL MOON
        *str--^
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Question 1.will cin.getline()only stream in 1 line, instead of cin >> file, and if so,how do you go about this with alphabetizing.. What I am thinking is: cin.getline() will stream in 1 line, maybe at a time, and then you can call the swapNames function after the first cin.getline(), and if that second line's first int is smaller than the first lines, switch the second line to the first.

How about read in each line and sort the lines using the bubble sort. You already suggested it.

Question 2. How do i go about converting the char array that has the text file in it, into integers. I've never had to do this, and I've heard it makes the process easier using int.

Good question. What integer would you convert "Jones, Frederick M" into?

And stop thinking in terms of character arrays. You already posted that you should "use the C++ string class." That solves all of your questions in one C++ type.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i know the number that doesnt work is when range gets changed to zero

so i want program to know that when range equals zero it doesnt have to guess to more, it should know that the number
i know you can do this with the else statement and that is where my trouble is how input that statement in my code.

Then I will rephrase:
With pencil and paper, go through your code line by line using the number that doesn't work and see what happens when you get to that range. What needs to change in the code right there.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Write one more function to return the number of digits in one of the arrays. Have it return the index of the leftmost digit. Call this function on each array and remember the lowest value (the leftmost digit of the 'largest' value).

Pass this value into the print function. You can take it from there.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you executing the code by hand to see what happens with the number that doesn't work? Follow each statement with pencil and paper and write down each variable and watch it change. You should find out where it goes wrong.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No. It's this:

Indent blocks of code 3 to 4 spaces. 2 is not quite enough, 5 is getting too much. Try not to use tabs because:

1. different programs may display tabs differently
2. most forums handle tabs badly

Usually tabs are 8 spaces, which means a 4th-block indent starts 32 spaces from the left border, which in itself makes code hard to read. Too much of a good thing...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Just open the file in binary mode and read it. Nothing magical or hard about it. You don't need APIs.

And in a computer, all values are numbers. And all bases (binary, decimal, hex) are equivalent. For example, if xval=66, all these statements test TRUE:

if (xval == 66)      // decimal 
    if (xval == 0x42)    // hex
    if (xval == 'B')     // character

There is no 'native' binary in C++. Hex is the closest we have

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i agree i've been looking at it and i'll try and figure it out, but would you guys mind helping me this has been stumping me the past 2 days.

Yes, if you will format the code. If it's true that this is the format your instructor is teaching, please change instructors. He is not a programmer. Sorry.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks for the fast response! That's a one way to do it but I was looking for something of the nature of traditional bubble sort. Comparing and swapping words next to each other and go through all the passes while there's a same character being compared, move on to the 2nd position of char and do sorting there. What I understand from the code you provided, it's comparing entire word to word, rather than individual characters of each positions-compare 1st char of words, if the char is the same, compare 2nd char and so on.

So in the standard BSort form, you need a K loop to look at individual characters. No biggie.

for i=0...
    for j=i...
        for k=.... ;; Loop through each character.

But, my way shows you a new and useful concept rather than simply adding to the known sort algorithm.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

My apologies this should be better

Somewhat. Please actually READ the link. There are still problems with your formatting. Yours, too, gerard4143...

Also is fgets just a security issue because the program still doesnt respond

What does this mean?

The problem you have is you didn't think through the problem yet. I'll bet you just started coding...

for(int i = 0; i < strlen(string1);i++){
        //selects the three characters to be compared
        for(int j = i; j < i + 3; j++){
            temp[j] = string1[j];
        }

If string1 is ABCDABCDE and i=8 what's going to happen in the j loop?

//pointer to where the occurance is
    ptr1 = strstr(string1,temp);

Which occurrence is this statement going to find?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
t[]={1,2,3,4,5,6,7}

and I need to remove 4 and 5 and then send the array back through all my functions.

So when you 'delete' 4 & 5, what does your array look like? t[]={1,2,3,-1,-1,6,7} -- if so, you can probably figure out how to do this. t[]={1,2,3,6,7} -- if so, you can probably figure out how to do this too.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Also, can't read your code. Please format it so we can. If we can't understand it we can't help.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Create a second array which contains indecies into your array of strings. For example:
ArrayList= "0hello", "1axe", "2help", "3nice", "4camper", "5ocean"
ArrayPntr= 0,1,2,3,4,5

Now as you test ArrayList use ArrayPntr to get at the values:

for i=0 to 5
    if ArrayList[ArrayPntr[i]] .GT. ArrayList[ArrayPntr[i+1]]
        swap only  ArrayPntr[i] and ArrayPntr[i+1]
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are inputting strings and you want the average of them? I guess first you need to explain this:

What is the average of "John", "Book", "Table", "Sheila" and "Europe"?

Answer that, and we can understand what you need...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Go through each element and keep track of the minimum and maximum values as you go. Also, add the element to a running sum and at the end divide by the number of elements.

Load the first value of the matrix into your min and max variables first. That gives you the first 'guess' at the answer. After all, it could be...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I repeat:

You are using the size of full to test characters in temp. Are you sure temp has >= characters than full? Display the values and see.

lexusdominus commented: a minimal amount of information solving a massive problem +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i have tried using

while(getchar()!='\n');

to clear the buffer , is there any other way / method? is there a simpler way to do this ?

Thanks

Can't get much simpler than that...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to look at what you are trying to accomplish as you go through your code.

And it would really help you do this if you format your code properly.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thank you. Now it makes a little sense. Still have no idea how to solve a problem, but at least I can see what's happening.

[rhetorical]
I wonder why cdrom fails to load? I don't even have a cdrom. Who's the smart-a$$ that decided it should load anyway? :icon_rolleyes:
[/rhetorical]

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at what? It seems to be an unreadable mess, not a clue where to even start.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

oh okay but arent headers just ways to assoiciatite a way of doing something with what you want to call it? so by that theory there should be a semi-standard way to clear the screen?

But using that theory, which is wrong to begin with, there must be a way to think of something and have it miraculously happen.

Maybe you need to read up on what a header file really is and what goes into one. And their limitations.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

as for windows.h i need to still use system("cls"), and conio.h was because i was going to use getchar() or getchar_ but i never got around to it so ill just delete that, but still, shouldnt somebody be able to look into the windows.h file and see how they make the screen clear?

There is no screen clear in C++. The fact is that C++ was not designed with the screen and keyboard in mind. It was designed to be a general computing language. The I/O design was never meant to be robust. Simply adequate. As for looking into windows.h to see how to clear the screen, do it. It's right there on your computer in the include directory for your compiler. Find it and post it here...

i have a hard time believe that theres no way to clear a terminal screen when people can make 3D games, and piplining encryption software,

That's because people wrote special code packages to interface with your graphics card, the screen, keyboard, mouse, etc. They are special and in no way part of the C++ language design.

bottom line i dont believe for a minute that you can build a spaceship without first knowing what combustion is.

Really? Therein lies your difficulty. You are concerned about combustion, and the spaceship we are designing works on anti-gravity.