Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I would have trouble, in theory, terminating the char array like this:
>>word[2] = 0;

Theory doesn't always hold water. Coding the above is perfectly legal in both C and C++. I know of no compiler that will produce either errors or warnings on that line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>you can't write a sentence that makes any sense.
Sorry for not being a scholar in English. >_>

We don't expect you to be. Just write sentences that people can understand -- grammer doesn't have to be perfect, just understandable. I still have not figured it out

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, I'm not understanding why are you all being so weird here. There totally no of TOTAL Just refer to your code.

Look who's calling the kettle black -- you can't write a sentence that makes any sense. :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

'\0' is the null character used to terminate strings in C/C++.

which is 0. Why? because the backlash '\' tells the compiler to interpret the next character litterally, it is one of the several escape characters in the c language.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Most of the time there is no reason to clear the buffer on each iteration if you know the byte count of the characters read from the stream. Post a little code and maybe we (everyone here) can help simplify it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

BTW lines 31 - 56 could be coded in just three lines of code, which includes a short loop.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not use std::string and you won't have to worry about the size because std::string will do that for you. Just call getline() to read the entire line.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>am i wrong??
Yes, you are wrong. You ALWAYS have to declare variables before they can be used. And on line 24 total is no different. pass by reference means that the receiving function ( display_output in your program) will have direct access to the referenced variables which must be declared somewhere in your program. So if display_output changes the value of total then that change will be visible when display_output returns to its caller -- in your program main().

And in case you have not figured it out yourself by now, line 45 is incorrect. You forgot the last parameter -- total.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This requires just simple division (2nd grade or so math )

Number of busses = number of people / 50

out of the remainder from the above, the number of vans = number of people / 15

What's left is the number of cars needed.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those errors mean that you prototyped the functions using the reference operator, but the actual functions get the paramets by value, not by reference. The functions, even though they have the same name, are not the same. Fix the problem as already pointed out a couple times before.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I found the solution to question i asked previously. But could someone please explain line by line what each line is doing. Thanx...

Why? So that you can plagiarize someone else's code and turn it in as your own work? Why don't you add your own comments to work out the logic.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> I'm receiving 4 errors
please post them.

my guess about the errors: The parameters on line 45 must match exactly line 6. Same with line 5 and 40.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>why do we need that
To complete the while statement. Normally putting a semicolon there would be a bug, but not in this case because there is nothing else to do.

>>It's too compact to be readable.
Then the reader doesn't know C language very well, probably a newbe. Looks perfectly ok to me.

>>The performance is deceptive (it's usually slower).
slower than what? possibly strcpy() is faster, depending on how the compiler optimized it.

>>The tricks used are obscure.
What tricks? And how are they obscure.

>>The mechanics are too subtle (notably, dealing with '\0').
Not subtle at all if you realize what that loop is doing.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>To do this, I somehow need to turn the int into a char of THAT INT, not the ascii character for that value.
Do you mean if you have an int with the value 15 then you want a string "15" so that you can display it in an edit control ? You can use sprintf() to do that, like this:

char buf[26];
int n = 15;
sprintf(buf,"%d", n);

Now after the above is executed you can send the edit control a message what displays the text in buf variable.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

create a new project then add the files to it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

see this There is no really good way to do it without some very serious side effects.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first one is an empty string, the second one is a single character 0 identical to the third one.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't mean to hijack this thread, but yes there may be a difference, but then again there might not be one also. depends on the compiler, which I'm sure you already know but other readers may not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It generates the same set of numbers every time because you didn't seed it. Do this:

#include <ctime>

int main()
{
     srand( time(0) ); // see the random number generator

    // other code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

WTF.. All she asked was the difference between ++i and i++, not such weird details.

I agree (beating a dead horse)-- but everyone has to get in his/here 2 cents worth :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

wanna learn just cause it seems fun

Its also illegal, so I'm closing this thread.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it gave me:
line 37: error: name lookup of `a' changed for new ISO `for' scoping
line 35: error: using obsolete binding at `a'

oops. you have to declare a, see line 2 below

cout << '\r';
int a;
for(a = 0; a < turn-1; a++)
    cout << '.';
cout << seq[a] << '(';
for(a = 0; a<turn; a++)
{
   cout << seq[a];
}
cout << ')';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>where in my code would that snippet go

Replace line 72 with that snippet. If your program still does not work then there are other logic errors that you have to figure out how to fix. Sorry, but I can't help you any more tonight.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this: (replace lines 30-33 with below)

cout << '\r';
for(a = 0; a < turn-1; a++)
    cout << '.';
cout << seq[a] << '(';
for(a = 0; a<turn; a++)
{
   cout << seq[a];
}
cout << ')';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Okay, so find me a country, any half democratic country, where infighting isn't an issue. You wanna tell me it's not an issue in the US, which is rather far from being a socialist country? Or how about England, or Japan...

We don't have infighting. What we have are debates :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

well, since I can't see the code on your monitor then you'll just have to post it here if you expect me to help you :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Provide for the "worst case in which all 20 numbers are different

>>Use the smallest possible array to solve this problem.

The answer is an array of 20.

please post your pseudo code that you have written so far.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh yes, I forgot. Here it is using string

string buf;
    getline(cin,buf);
    if( buf[0] == '@')
        return '@';       
    binary = atol(buf.c_str());

And there are other c++ ways to make the conversion on the last like of the code above.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know about the output thing you posted -- I have no idea that how to generate it. But in *nix exclude windows.h and intead of Sleep you can use the *nix version sleep or usleep

>>they are having us use PUTTY
Uggggly! That's just insane and makes me want to puke. Are you sure you are taking a c++ course ? What c++ compiler are you using that does not support cout ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Oh yes -- now I see the problem. cin is attempting to get an integer from the keyboard, but errors when a non-digit character is entered. What I would do is get the input as a character array (or c++ string) then check -- starting on line 77 in your program.

char buf[16] = {0};
    cin.getline(buf,sizeof(buf));
    if( buf[0] == '@')
        return '@';       
    binary = atol(buf);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to use an os-specific function to delay the program a bit inside the loop. If you are using MS-Windows you can include windows.h and call Sleep function.

>>cout<<"\010."<<flush;
Thats poorly written. flush is not normally needed. Below is normally how to move the cursor back to the beginning of the line so that succeeding output will overwrite existing characters on the screen.

cout << '\r';

Here is a complete example

#include <windows.h>
#include <iomanip>
#include <iostream>

using namespace std;


int main()
{
   for(int i = 0; i < 10; i++)
   {
       cout << '\r' << setw(2) << right << i;
       Sleep(1000);
   }

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can code member functions either before or after main(). If they are coded after, then you have to provide function prototypes at the beginning of your program. For example lets say you want to write a function foo that takes an int argument and returns an int. Code it like this:

#include <blabla>

// function prototype
int foo(int);

int main()
{
   // blabla
   return 0;
}

int foo(int n)
{
  // blabla
  return 0;
}

see google for more detailed tutorials

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Every character you can type on the keyboard is entered into your program as an int. The char data type is really a one-byte integer. There is no such thing in C and C++ as a character data type. So if the '@' character is causing your program problems then it is due to a bug in your program. But since I can't see your code from where I am sitting I suppose you will just have to post it here for public display.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think your problem is the way you are using ListViewText array beginning at line 272. This is a better way to do it. Note there is NO dynamic allocation needed and only one character buffer. You are allowed (and encouraged) to reuse data whenever possible and wherever it makes sense.

Note that I have added a couple lines to resize the vector to the correct number of elements. That was one of the main reasons your code did not work -- you were setting strings to non-existant rows and columns. I have not tested this code, but I THINK it will work.

vector< vector<string> > ListViewText;
            ListViewText.resize(NumOfItems);
            char text char[256];
            for(i= 0; i < NumOfItems; i++)
            {
                ListViewText[i].resize(2);
                ListView_GetItemText(hWndListView, i, 0, text, 256);
                ListViewText[i][0] = text;
                ListView_GetItemText(hWndListView, i, 1, text, 256);
                ListViewText[i][1] = text;
            }

Another problem with the above is: so what? You are putting all the strings in a 2d vector of strings which are immediately destroyed because of where that vector is declared. What do you intend to do with it ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Would you please also post resource.h so that I can compile it ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your old DOS compiler probably supports stdprn, just as it does stdin, stdout and stderr. If so, then just print to stdprn

fprintf(stdprn,"Hello World\n");

But your compiler can not access network printers -- the printer must be on LPT1.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, don't allocate the buffers like that. Its just toooo much! If you want to use dynamic allocation then allocate them before the loop and delete them after the loop terminates.

>>But I don't know how to move to the next item
Increment the second parameter ??

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why don't you replace the ifstream and ofstream objects with just one fstream object then open it for both input and output, in binary mode.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I want the user to enter as many food items as they wish.When the user is done entering food items ,display the total number of food items,the total cost of thelunch and the total number of calories .

Ok, so what doesn't your program do that it should do? What have you tried to fix those problems ? (Hint: we are not going to write your program for you. That your job, not ours. )

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We can draw straight lines and boxes with simple c or c++ console programs because MS-DOS supports the Extended Ascii character set (characters above 127 decimal). But forget doing circles, curves or anything more complicated with standard console programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why isn't it free ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are we using ? And why are we mixing C functions with c++ code? If you are going to write are c++ program then do so. Yea I know c++ language supports those c functions but its a lot better style to use all c++.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler do you have ? You can get some old MS-DOS stuff here. They are not tutorials but actual working example programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

moved

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can you help me with this
Sorry, sadly I'm not really all that good at that either in c++, I know the basics. Hopefully someone else will read this and give you a hand. In the meantime I suggest you just test out different things to see if you can get it to work yourself.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>and what about line 24 and 25 do they need to be changed?
No, leave them alone because you have not finished that code yet. After fixing all those lines you mentioned I suspect you need to add more code to read the variables from a data file so that they can be displayed on the screen. But you haven't said anything about that data file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

ouch!!!! my butt hurts just looking at that. That sport looks like alot of fun, but ....

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is that some wife's tale you quoted ? :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>WHAT IF I JUST WANT IT TO DISPLAY ON THE COMPUTER SCREEN AND NOT TO A FILE
Please don't use all caps like that -- its like screaming at us. If you want to display something on the screen then use cout

cout << "Hello World\n";

The above will show the text on the screen. Notice that OUTPUT always use the << operator, and INPUT uses the >> operator. The two can not be confused or used interchangeably.

line 17 should be coded like below. Note that it does not use indata variable at all, but uses the standard c++ cout which is declared for you in iostream header file.

cout << left << setw(22) << "Federal Tax" << right << setw(14) << federal << endl;