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

Look up
strcmp()
strchr()
strcpy()
strncpy()

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

Thread's done...

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

write C++ program to print the sum and average of 1 to 10 using for loop?

Easy peasy. Why do you ask?

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

You've defined your ifs

if ()
{
else
}

It should be

if ()
{
} <===== you need this
else
{ <===== and this
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I need to two loops in the switch correct? one to read in the information and one to put the output in the struct.

Why? What's the switch supposed to do?

You aren't thinking this through. You're taking a poorly designed program and trying to shoehorn in fixes that may or may not work. You'll never get it this way.

You need to take your problem statement and sit at a desk (no computer) and start writing down the individual steps you need to do to accomplish the task. Smallest steps possible.

Then order those steps in a logical order.

When -- on paper -- your algorithm (the list) looks like it will do the job, now go to the computer and code it. You can do it the hard way and plagiarize what you currently have, or start over.

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

Sorry, I disagree with most of what therockon7throw said...

We call C++(C PLUS PLUS ) because it has been taking his way from old C, and has brought many many concept , OOP (Object Oriented Programming) , STD, ADS , template and finally Meta Programming. C++ without these features would be just C.

This I agree with.

With C you write a program, but with C++ you manipulate the program itself.

This I don't. You aren't manipulating the program, you're manipulating the data via the programming.

So to summarize, learn first C++ as well as you can, and if you are a master of C++, there is no language on the earth that you can not learn in just a week.

And this is just blatantly wrong. There are many, many languages that knowledge of C++ won't help one iota in learning.
Lisp
Snobol
Bliss
RPG
Assembly
Cobol
Prolog

just to name a few.

And the argument "I've never heard of them" doesn't apply. They exist and are in use.

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

the obvious would be to compare the entered_PW to the actual_PW but looking back over the rest of the code i think i forgot to assign each digit in the actual_PW to the random 1-3. how could i do this? or is

actual_PW[index] = random_Nums[index];

sufficient?

That's seems to be exactly what the function is for, so yes.

in this iteration it couldn't return true, and that is mostly because i hadnt fully figured out what i needed to compare to get the true.

heres an update on that function

bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
    {
        bool valid = false;
//*****************************This is where i'm having trouble**********************************
        for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
            {
                actual_PW[index] = random_Nums[index];

                if (entered_PW[index] == actual_PW[index])
                    {
                    valid = true;
                    }
                else
                    valid = false;
            }
        return valid;
    }

Your thinking is backwards. If any values are TRUE, this function returns TRUE.

When creating a function that returns an all-or-nothing comparison, like this function, it's best to start by setting the response to 'all' (TRUE). Then during the the testing, if any value fails, a single FALSE comparison sets the result to FALSE.

The way you have it, the result assumes FALSE. Then during the the testing, if any value succeeds, that single TRUE comparison sets the result to TRUE. Clearly not what you want.

Think of this as an ANDing function. Any fail returns FALSE, All successes return TRUE. Yours is an ORing function.

But …

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

From his brain. He wrote it.

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

Maybe so, but I was asking passionated so he can learn something, not to have the questions answered by someone else so he doesn't have to think. Just sayin'.

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

Result: case 1 = 83413 clock ticks, case 2 = 37,753 or less than have the time of case 1. The time difference could be even greater had I used a more efficient sort algorithm.

Aha -- that's why! Thanks for clearing that up.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
bool isValid(int actual_PW[], int entered_PW[], int random_Nums[])
    {
        bool valid = false;
//*****************************This is where i'm having trouble**********************************
        for (int index = 0; (!valid) && (index < sizeof(actual_PW)); index++)
            {
                random_Nums[index] = actual_PW[index];
                if (entered_PW[index] != )
                    {
                    valid = false;
                    }
            }
        return valid;
    }

#1) If you are trying to compare the password entered (entered_PW[]) with the actual password (actual_PW[]), why is random_Nums[] needed to check validity?
#2) What is the purpose of random_Nums[index] = actual_PW[index]; ?
#3) What is the obvious comparison for entered_PW[index] in the IF ?
#4) If you only set valid to FALSE, how can it return TRUE?

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

And I don't understand what your problem is.

You have all the values accessible.
You know how to convert a control's text field into a value.
You know how to add two values.
You know how to load a value into a control's text field.

Clearly you are having a specific problem that your general description does not address.

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

In my first post, first sentence, I clearly said

The key to recursion is the value returned from the function. That's your main problem.

Use the return statement -- that's what it's used for!!!

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

Read my post again. You didn't even consider half of it.

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

Didn't the very first post in this forum at the top help any? You know, the one titled C++ Books?

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

Divide by 1000.0

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

If you say so. I'm dubious.

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

Depends on what you want it to do. You have to figure that out and write the function.

Or is there a different problem you have not expressed correctly?

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

The key to recursion is the value returned from the function. That's your main problem.

Next you haven't properly defined what the function is supposed to do. Does it
A) return a reversed value of the integer passed to it?
B) simply print out the individual digits in reverse order?
C) create the reversed value and print it?

The way recursion works is it will either
1) calculate one value then calls itself with the rest of the number
2) remove a digit, call itself with the new value, upon returning get the digit to from the value.

The way recursion remembers is all the values it calculates in 1 instance of the function remain in that instance. When the function calls itself, it makes a clone of the function complete with all new values. When the function returns, it back through all these instances which 'restores' the values from that instance.

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

Run the program sir and enter any file name with extension file of txt and choice number 1 add records then desplay the record by chosing number 3 that code is in parallel i want in vertical.

No sir, you post what the program displays and what you want it to display. That's the price of asking for help -- giving us the information we need to understand.

Be sure to use the proper tags so we see exactly what you want us to see.

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

WaltP: I realize this, but when I try to change *AccName to AccName I get an error (invalid conversion from const char* to char).

char Account::getName() const ^ defines a single character return. You want it to return a string.

Just for reference here is the definition for the original method:

char getName() const;

If the original method won't work as defined, fix it so it will.

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

I've never understood all this sorting of linked lists. Why not just add the node between the nodes containing the values above and below the new node? Just add them in their sorted position!

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

1) Your switch function has no value at all for rank
2) You return a nonexistent variable named rankPay

Think it through again. What values do you have available in the function? What values do you need to have for the calculations? If you don't have them in the function, how can you get them there?

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

Thank You WaltP for pointing me to fgetc()

You're welcome....

I was looking through the MAN pages and was able to fix my problem by using ftell() to see if the offset stopped changing after each read as follows:

Terrible idea. Why not just test the return of fgetc() and process the error or EOF?

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

Hey passionated, you should only log in under one username. You should not use the savoie username too, especially in the same thread.

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

Where is sleep() defined?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
char Account::getName() const
         {
         return *AccName;
         }

is defined to return a single character, which is exactly what us happening. *AccName points to the first character in AccName.

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

Let's keep helping the guy that hasn't been here since July last year....

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

For me the question would be why would you use fscanf() to read a single character when fgetc() does it much more efficiently?

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

Use CODE Tags!!!

char a;            // define a character
scanf("%d", &a);   // read an INTEGER into the character
printf("%s", &a);  // print the character as a STRING

You tell Us what's wrong with the code...

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

Then I have no idea what you're asking since the problem as you stated it is cryptic at best. Try giving us some details that explain exactly what is going on.

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

We don't bump here.

The reason I haven't answered is your comments were nonsense based on my previous post:

That just multiplies the first input by two.

And your following question makes no sense for anyone with 2nd grade math:

How can it add new items inputed from the user in the textbox to the labels? So lets say i put in 35, it will show subtotal of 35, tax of 1.05, shipping 15, and total of 51.05. Now if i put in another number like 40 I would want it to add it to the subtotal, tax, and total of the first.

Use the + sign somewhere in your code to add the new values to the old values.

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

Try printing all the values to see which ones are wrong...

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

First half of string 1 would be: This is the
Second half of string 2 would be: ul things up takes a computer

It would display as: "This it the ul things up takes a computer"

How do you figure this?
What did you do to arrive at "This is the" and "ul things up takes a computer"?
Put that into code...

How long is a sentence? How can you figure that out in code?
What's half a sentence?
etc, etc...
'Tis simplicity itself when you stop thinking in terms of the end product, and think in terms of one step at a time.

Remember, a journey of a thousand miles begins with a single step. Then another. And another. Until you drop 10 feet before the gate in exhaustion. No wait -- that's not how it goes. :icon_wink:

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

Given: sentence 1 = "This it the time to fly"
Given: sentence 2 = ""To err is human, to really foul things up takes a computer"

What is the resulting sentence supposed to be? Not by computer. By definition of the assignment.

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

It runs fine and there are no syntax errors what-so-ever, but I'm not 100 percent sure the math is right.

Then whip out your calculator and test it.
Pick several cases form short to tall height and a single acceleration, calculate it old-school and see if your program agrees.

Then do the same for various accelerations holding the height constant.

Be sure to also test limits like height=0, acc=0, and the like.

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

Certainly looks self-explanatory to me. You can't make a char* (sString array) equal to a single character ('s')

If you think you "must be mixing up my char * and char" then look at the statements in question and verify it. Why ask if that's what you think and waste an hour waiting for us to confirm and spoon feed an answer?

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

Organizing it is important, but not quite as important as making it functional (and following the actual instructions).

I completely disagree.
A good organization is best done when designing and writing the code -- long before it's functional. This makes making it functional easier.

Organizing after it's functional simply means
1) it takes longer to get it functional
2) a lot of work getting the mess organized after it's functional
3) fixing the code after organization has broken it.
IOW - it takes 3-4 times longer to create a single program.

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

Well, let's follow your code:

void LL::decrement(int NewNum)
{
  int id;           // create ID with some unknown value
  int temp;         // create TEMP with some unknown value
  PCB *x = front; 
  if(x->id != 1) 
    {
      while(x!= NULL) 
        {
          x->id = temp;      // Load the unknown value TEMP into your structure ID
          NewNum = temp - 1; // Decrement the unknown TEMP value and put it in NewNum
          x = x->next;  
        }
    }
}

When you return, nothing happened to NewNum since you didn't pass the address
x->id got trashed

Looks like you need to think through your process again.
And check out how to do assignment statements.

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

Where are you adding the number of evens? All I see is you returning 1.

Also, you aren't breaking out of your recursion.
You test if n is even and return 1.
If n is odd, you call the function again.
But you don't count the evens, and you don't exit/return if you run out of digits.

What you need to do is call the function like you do with your n/10
When n enters as zero, start your return cycle.
If value is even, count it
Return the count.

chaoz014 commented: thank you very much... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why are you using StdAfx.h? That's your major problem.

Write the code based on the C++ Standard and the program should compile in both environments. Don't use any of Visual Studio's cutesy enhancements at all.

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

As I posted elsewhere

Try printing out a copy of your program, grab some paper and a pencil. Sit down at a desk or a table.

Start at the first executable statement in main() and follow the program statement by statement. Write down the values of all variables. Write down everything that is displayed. IOW, you be the computer and desk-check your program.

This is a fundamental part of programming -- checking your work.

Do the same with the algorithm you are trying to implement and note where your program and the algorithm seem to coincide -- and there they diverge.

All you seem to be doing is throwing new changes around without understanding what those changes really do. In fact you probably don't quite understand what the program is really doing at the moment (I know this because if you did know it would be obvious to you what to change).

Use the technique quoted above to understand what you wrote. And that will tell you what you need to fix.

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

Calculate the new values for subtotal, tax, and total and put them in whatever control displays the values txtSubtotal.text = subtotal or lblTax.caption = tax

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

But I want the strings only after EXEC and before END-EXEC... ie from POLICY_NO to CAN_PROCESSED...

So read the strings up to EXEC and don't do anything with them.
Then read the strings up to END-EXEC and use them.

Hint: two loops.

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

why you use strcat() method....you can try use loop read char by char and place in third string

My guess is that the purpose of the function is to concatinate strings, which is also (surprisingly) the object of the assignment.

What do you put if the position of the beginning of the second half is unknown, since this is from user input?

If you don't know where "the position of the beginning of the second half is, you can't do the program. I assume you need to figure out where the second half starts.

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

OK, you posted your assignment. You posted your code. But you didn't explain exactly what you want help with. "Organize" is not a specific enough question. Although proper formatting would be a really good start. It helps you. It helps us. And your instructor won't have to work so hard checking the code so it helps him, too.

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

strcat (string3, &string2[start-of-second-half]); This passes the address of the position of string2 you want to add.

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

You might have missed a bracket somewhere... Only such a mistake causes so many insignificant errors.

And to find it, format your code properly. It's your first debugging tool.

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

Not one question was asked. Not one problem was explained. All that you said was "now I am trying to total the number of students, then compute the distribution". So do it.

If you're having a problem, you need to explain what it is.