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

>>but can anyone write some code in C using if statements for the following:


No! write it yourself, post code and ask questions. we do not do your work for you.

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

>> cin >> filename;
If there are spaces in the filename and/or path the above will not work because it stops at the first space. In that case use getline().

while(!file_in.eof())   //as long as we're not at the end of the file....do
 {
  file_in >> temp;   //reads file into a temporary file     
  total = total + temp;  
  counter++;     //adds one to the counter
 }

The above is the incorrect way to code the loop -- do not use eof() because it will go through the loop one time too many.
Here is the correct way to code it.

while( file_in >> temp )
 {
  total = total + temp;  
  counter++;     //adds one to the counter
 }

>> for(int i=0; i<=100;i++)
The above loop is incorrect -- it counts one too many times. remove the '=' symbol, like this
for(int i=0; i < 100;i++)

>> double average = total/counter;
the value of counter is 0, so your program will get a divide by zero error at runtime.

there are probably other errors, but I stopped reading. fix these and repost if you have more questions.

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

16-bit api functions are obsolete and were only useful on now dead MS-DOS 6.X and earlier operating systems. Don't bother with them. If you use a 32-bit compiler you can't use them anyway.

Here is a good 32-bit tutorial that you should learn.

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

I got the same one -- manybe everybody does??? The most difficult questions for me were to select the picture that was least like the others. my favorits were the brain teasers. Too bad they didn't say which questions were incorrect.

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

read this

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

In C++ functions can have parameters with default values

int Test ( int a = 1, int b = 2)
   {
      return a * b ;
    }

now when the program calls Test with no parameters, the compiler will force them to the values shown above.

int return_value = Test();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it always helps to post the code that does not work. and please use code tags as explained in the threads at the top of this board.

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

Hope that counts as one time weighting :P

Nope, it doesn't. And the king already knows who makes what trinkets. Its not a balance type scale but a scale that displays the weight of whatever is put on it.

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

1. Please edit your post to use code tags to preserve spacing and tabs.


2. main() must be declared like this:

int main()
{
   // blabla


  return 0;
}

I realize neither of the above answer your questions, but fix those and we will look at your post again.

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

This is a really old one -- you might or might not have heard it before, but an easy one to do in your head.

A king has 10 slaves. Each slave makes a gold trinket with a unique design and weighs exacely 1 oz. One day the king learns that one of his slaves is stealing some of the gold and his trinkets weigh something less than 1 oz. Using a scale and with only one weighing how can the king find out who the thief is ?

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

Ah Ha! my original solution was almost there --
(40/5) * 2 = 16
he gets another 20 on day 17, so on day 17 he has Rs 60 in his hand.

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

Impossible question to answer -- how many Rs did he start with? how many did he get from his sister, mother, father, aunt, uncle ... ? How much did he have in his piggy bank? He certainly did not earn 60 on any given day, so that's obviously not the right answer. I'm going to stop guessing and let someone else try to guess. :)

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

on which day he will be having Rs 60

I assumed that meant on which day will he have accumulated Rs 60. If that is an incorrect assumption, then please explain what it means.

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

at the end of every other day he will have Rs 5 left. So the answer must be (60/5) * 2 = 24th day.

BTY: what is Rs ?

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

boaland 5.5 and earlier have the same problem as VC++ 6.0 -- they are too old and do not support current C++ standards very well. And that is a big problem for new people who are trying to learn modern c++ with an ancient compiler. There are a few legatimate reasons I can think of for using those old compilers (such as support of legacy programs) but most people should be using newer compilers. when you say "they work" do you mean they work with code written in 2006 or code written in the 1980s and 1990s (10 years is a lifetime in the software and compiler industries!) The last time c++ standards were upgraded was in 1999 which is well after those borland and microsoft vc++ 6.0 compilers were produced.

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

shouldn't be difficult -- search for '\' and if found assume remaining word is a hext digit. you can use strtol() to convert to a long and typecast to char.

char *ptr;
char hex[] = "7C";
long n = strtol(hex,&ptr,16);
cout << (char)n;
//
// or to convert back to a string
char buf[255];
sprintf(buf,"My name is John %c", (char)n);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

read the stickies at the top of this form -- that contains lots of information and links, for example this one

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

1. step #1 -- go to Add/Remove Programs and remove that old ancient compiler from your computer.

2. Setp #2, to do Microsoft Web site and download VC++ 2005 Express and the Windows Platform SDK.

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

Depends on which version of that compiler is used -- 16-bit MS-DOS or 32-bit MS-Windows? 16-bit can create arrays up to only 64,000 bytes (large memory model), or 16,000 long integers. There is no work-around other than to redesign your program or use a modern 32-bit compiler, which is one reason MS-DOS is dead and buried.

Salem commented: Nice - Salem +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

yes, I knew that would happen. Please look at my post very carefully because I showed you the correction -- two '\' characters.

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

we certainly cannot accuse him of talking too much :mrgreen:

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

God will bless you~gustylow.
You will get the best present- a lovely baby
and what do you think about your baby's name?

Yes, you will have to let us all know when the happy event occurs:) As for a name -- hummm -- maybe DaniWeb :mrgreen:

And welcome to the boards.

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

Welcome to DaniWeb -- I don't know a thing about Pyhthon so I can't help you at all with that. Hope you have enjoyable experience here.

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

welcome to DaniWeb -- and happy to find someone my own age group.:mrgreen: Hope to see you around these forums a lot. And enjoy that grandson as much as you can, as you know they grow up so fast. I live only a couple hours drive from you so maybe we can have a virtual beet together :cheesy:

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

use the escape sequence character. and to get the '\' you need two of them

sep = strpbrk(line, "\\<=->/'\"");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

c or c++? read all the words into an array of strings then use either C's qsort() function or c++ sort(). If you are required to write your own sort routine then you can't use either of those functions. in that case, google for "sort algorithms" and you will find quite a few of them. Bubble Sort is the easiest to code but can be the slowest to execute.

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

read the stickies at the top of this board -- they will give you lots of information and links.

and Welcome to DaniWeb. Please visit Coffee House and introduce yourself.:)

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

hmm, i dont really get it. so i have to malloc each of the array (ie using loop, allocate space for each structure in the array)?

int i = 0;
for (i = 0; i < MAX_NUM; i++) {      //MAX_NUM == array size
array[i] = (StatusPointer) malloc (sizeof (struct status));
}

Yes like that. Unless your assignment requires you to use pointers -- why use them? just statically allocate all those structures and it will cause fewer problems.

struct allStatus {
struct status  array[MAX_NUM];
};

and also, should i put it before group1 mem allocation, or after ?

memory must be allocated from the outermost structure to the innermost -- and free'ed in the opposite order.

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

that is the right syntax, but it does not allocate enough memory because array inside the allStatus structure is an array of pointers and each of them must be malloc'ed as well.

[edit]Sorry Glorious -- your post was not there when I started writing the above[/edit]

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

mind explaining what you are talking about?

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

my quess is Expr1Column is the name of a function, if that is correct then you need to add the parentheses

if (LogInfo.Expr1Column() > 0)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You know the ID of each text box, right? And you have the HWND of the dialog box that contains the edit controls, right? Then use GetWindowText() for each box

char text[255]; // or however long the strings are
// hWnd is the HWND of the dialog box
HWND hEditWnd = GetDlgItem(hWnd,IDC_EDIT1);
// get 1st text box
GetWindowText(hEditWnd, text);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>typedef basic_string<unsigned char> ustring;
above is unnecessary. just use c++ string class. so you might as well delete that line.

>>inData>>Name>>iNum;
If there are spaces in the name then above will not work because extraction operator >> stops at the first space. In that case you need to use getline() to read the whole like then extract the last word as the number.

you will need an array of name strings so that they can be printed later in the program, then read name strings into this array similar to how yu read the iNum array.

std::string Names[50];

It is not necessary to calculate the average until after all reads are complete. Your program only needs to do that once, at the end.

Do not attempt to print out the names of those whose scores are below average until all 50 names have been read because the program doesn't know what the average is until then. After reading is finished, calculate the average then have another loop test each of the scores against this average and print the names when necessary.

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

Please use CODE TAGS All that unformatted code hurts my eyes and greatly reduces the probability that anyone will help you.

Also we do not do student's homework.

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

>> while(Pds >100);

that is an infinite loop because of the semicolon at the end. Your program will never stop executing that loop because the value os Pds never changes. This is a common error that everybody counters on occasion due to carelessness.

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

I'm sure you know what files are -- If you are using MS-Windows operating system and use Windows Explorer you will see hundreds of files and folders on your computer.

Normally when programmers use the terms "read a number" it means to read it from a data file. But I may have misunderstood your requirements. If that is the case, then just use cin to read the values from the keyboard

#include <iostream>
using namespace std;

int main()
{
   int number;
   cout << "Enter a number";
   cin >> number;
   // now you must flush the keyboard of the <Enter> key
   cin.ignore();

   return 0;
}

>>I definitely wouldn't understand how to get the sum by upgrading it after reading each value

I already posted the example -- the line sum += number;
. The += operator means to add number to the previous value of sum. Just a shorthand way of saying this:

sum = sum + number;

from what you posted previously, you need to put the prompt for a number INSIDE the for loop.

cout << "how many numbers you want added? " << endl;
cin >> a;
cin.ignore(); // flush keyboard of <Enter> key

// on this for loop, we want to increment the variable [b]counter[/b]
// until it reaches the value of variable [b]a[/b].
for ( int counter = 0; counter <  a;  counter++)
{
cout << "enter a number: " << endl;
cin >> b;
cin.ignore(); // flush keyboard of …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you will want to investigate Reverse Polish Notation as it is applied to calculators. google has lots of information about it.

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

I got it!!! now how in the hell do I add increments? I'm stuck on this... I know this looks busy but this was thru trial and error tonight... I'm so proud of me!!!:mrgreen:

{
int a = 0;
int b =0;
int sum =0;
int counter =0;
int number =a; 
{
cout << "how many numbers you want added? " << endl;
cin >> a;
cout << "number to increment? " << endl;
cin >> b;
 
     for ( int counter = b; counter <= a * b;  counter+= b )
cout << counter << " ";
 
    [B] sum = b * ;[/B]
cout << "Sum is: " << sum << endl;
 
 
}

you have completly missed the point of the assigment. You must get the numbers from a data file, not from the keyboard. You have to use an ifstream object to read the numbers from a file.

As for getting the sum -- just upgrade the sum after reading each value;

int number;
int nitems;
ifstream infile("file.txt");
// find number of items to read
infile >> nitems;
loop starts here
   // read a number
   infile >> number;
   sum += number;
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please edit your post to use code tags -- all that unformatted code hurts my eyes.

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

you could make foo1 a base class

class foo1()
{
// blabla
};

class foo : private foo1
{
  // blabla
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

something like this: note, we are not going to write the program for you.

open the file
do this until end-of-file is reached
    use extraction operator >> to read a word
    check each character  and remove any non-alphabetic characters
          (hint:  isalpha() macro will help you do make that check)
    add the word to a std::string object
end of while loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your program should read the first number -- 5 in your example -- then have a loop that reads that many more numbers. If the file contains more than one line like that, the program should have an outer loop that performs those actions for each line in the file.

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

all I see from the original post is a picture that has a stack of CDs next to a few books. Pretty picture, but I don't think it contains anything illegal. maybe the immage was changed since the original post???

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

>>char wksales[rows][columns];

you did not change this like I suggested. wksales can NOT be a 2d array of characters. The instructions say you need a 1d array of ints.

//for( i = 0; i <rows; i++) 
{
int wksales[rows];
 
inFile >> wksales[i];
 
}

above is useless crap. you may as well delete it.

int wkdays[rows];

// read all the rows, ignore the first two integers
int i = 0;
int a,b,c;
while( i < rows && InFile >> a >> b >> c)
{
    wkdays[i] = c;
    ++i;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The file is in Notepad so I used that code.I also change the char array to int it's not working.

Post your latest code -- we are not mind readers and I don't have my crystle ball with me today :)

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

1. is the input file (data.txt) a binary file or a text file? If you can read it with Notepad.exe then its a text file, otherwise if the data is unreadable then its a binary file. Only binary files are read with iostream.read() function, text files use getline() or the imput operator >>.

2. wdsales() is a 2d character array. If data.txt is a binary file then you need an integer array

int wksales[rows];

infile.read ( &wksales [i], sizeof(int) )

if data.txt is a text file, then read it like this

int wksales[rows];

infile >> wksales[i];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We are all students -- some are just more experienced than others. I have been a student of computer programming for the last 30 years or so and feel like I am still learning this stuff. So just because you get a degree does not mean you will not stop being a student.;)

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

stop using scanf() because it may corrupt the input buffer and leave keys in the keyboard buffer. use fgets() instead

float num;
char buf[16];
printf("blabla");
// get input from user
fgets(buf,sizeof(buf),stdin);
// convert to float
num = atof(buf);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

getline() in the posted example is probably his own C function because the parameters are incorrect for the c++ version. May I suggest you look in semaphore.h and see if there is a marco you need to define.