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

cin.get() will not work either if there are still keystroks in the keyboard buffer. You will have to flush them out first. Here is a thread that shows you how to do that.


[edit]Oops! same as ^^^ said.

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

Yes they should return an int, but the author probably omitted that just to simplify the code and illustrate the intended problem.

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

You could try this or this to get examples

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

>>operand!='+' || operand!='-';

Use && operator instead of ||. Read the statement aloud to yourself -- "do while operand not + and while operand not -.

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

Your program seems to be doing it correctly. But I don't see where you declared variable named sum.

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

>>My friend needs a program that will:

That's nice -- now when are you going to write it for him? We certainly will not without a lot of $$$$.

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

1. you don't need that while loop that starts on line 5 so just delete it2.

2. The for loop sould cout from 0 to < size, not <= size-1. If the value of size is 5, then you want it to count 0, 1, 2, 3 and 4.

3. Use a do loop to verify the value of rainfall >= 0, something like this

do {
   ask question
   input value of rainfall
} while( rainfall < 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why you dont try fread() and fwrite() function which are capable of reading and whole structure at once example of fwrite()

Because he's only reading words from some text file, not the structure.

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

The structure is declared incorrectly -- wrd needs to be a pointer so that it can be allocated at runtime.

struct word {
    int count; // counter to use the word's occurrence
    char* wrd;
}*wordptr[50];

line 21: >>wordptr[position] = (struct word *) malloc(sizeof(struct word));

You need to do two things here
1. allocate an instance of the structure because the array is just an array of pointers. All the pointers have to be allocated memory before they can be used.
2. Allocate memory for wrd within the structure.

wordptr[position] = malloc(sizeof(struct word));
wordptr[position]->wrd = malloc( strlen(temp)+1 );
// now you can copy temp into wrd
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those pictures are called avatars, and are available to anyone. Set yours in the CONTROL PANEL link found at the top of each DaniWeb page. Everyone also have titles, but certain members can create their own title (admins, past and current mods, and those who donate their money to DaniWeb, called Sponsors)

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

That link works ok, but it does not sole the OPs question.

@valkyrie: You will want to ask the question(s) in another thead so that the main thread can cancel it out when the time has expired. Something on this order (assuming MS-Windows operating system). Note that you don't have to use clock() at all.

int questionThread(void* ptr)
{
   // display and ask a question here
}

int main()
{
   for each question
   {
     create thread using questionThread()
     wait for thread to finish normally or timeout expires.  WaitForSingleObject() will do that for you.
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your link appears to be broken -- I get an IE error that the page can not be displayed.

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

>> if(foo())

But Hello World should be displayed regardless of the return value of foo(), and the || 1 causes that. So you can't just toss out that or condition.

Fbody commented: Nice catch. :) +5
VernonDozier commented: Yep, good catch. +13
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

With VC++ 2010 look in <cctype> and you will find that it's in std namespace, just as Narue said it is. _STD_BEGIN is defined as #define _STD_BEGIN namespace std { in yvals.h

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

No -- reverse the order of lines 5 and 6. As it is, line 6 will never get executed because the function exits on line 5.

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

1. No
2. Yes, providing you reallocate the memory before attempting to use it. .

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

If you want to convert it yourself then amnt=money*10+1; is incorrect. Should be something like below -- you can not assume the string contains all numeric digits.

while( isdigit(money[i]) )
{
    amnt = (amt*10) + money[i] - '0';
    ++i;
}

Now do something similar for the cents. You might have to use another variable for this, then put the two together.

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

There are at least three ways to launch a process -- system(), ShellExecute() and CreteProcess(). Which one you want to use depends on how much control you want over the newly created process. google for those functions and you will see how to use them. CreateProcess() is the most complicated, but also gives you the most control.

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

You could start here -- be prepared for a very long learning curve.

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

Depends. What operating system? For MS-Windows, do you want to use pure win32 api functions? If yes, here is a tutorial. But there are a lot easier ways to write gui programs nowdays. Two of them is CLR/C++ Windows Forms, and C# instead of C.

If you are thinking *nix, then look into low-level X11R6 (there are lots of books on that) or Motief. Again, C++ gives you more and easier options, sich as wxWidgets.

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

Your program should run ok on 64-bit computers even without recompiling it. The only reason I can think of to recompile that program is to take advantage of the additional memory that 64-bit machines can give it.

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

First check your computer to see if winsock2.h actually exists. If it does, then you probably need to make a change to the list of folders that the compiler uses. You will find that list in Tools or Options menu item. I don't have that compiler installed any more but you will find standard compiler search folders somewhere there.

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

GetCurrentThread() will return the HANDLE of the current thread, which you can pass to GetThreadId().

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

Unless your instructor required you to use Dev-C++, you should replace it with Code::Blocks because Dev-C++ has not been updated for quite a few years and contains a very old version of gcc compiler. Code::Blocks is also free and current.

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

Do you mean thread ID or window id? All the windows in the same thread of the same thread ID, but each one has its own Window ID (or HWND handle).

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

just add -lm on the same line as gcc, such as gcc -o new prog.c -lm

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

post the entire code

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

what did you enter for a and b, and what were the results?

mitrmkar commented: A good question +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

make sure to include math.h

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

Search www.amazon.com for mfc c++ books and pay close attention to when they were published, also check the reviews. Those published within the past two years should be ok.

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

The loop for the cout statement is backwards for(i = 9; i >= 0; i--)

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

Re-read my comments. The statement about lines 5 and 27 is not related to the comment about input array.

Comments by other members in this thread are also valid, so the OP should read them all

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

>>I'm using Visual Studio 2008 and referencing a book called "MFC Programming with Visual C++ 6"


Get a newer book because MFC changed a lot between VC++ 6.0 and VC++ 2008. The two are not compatible, although you could make it work if you already know MFC well enough. Since you are just starting it would be a lot easier if you just bought a newer book.

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

You don't have to read it all at one time, but you do have to read all of it. Use a loop to read unwanted fields and just toss them out

char buf[255];
// read first 10 fields
int i;
for(i = 0; i < 10; i++)
   fscanf(fp, "%s,",buf);  // something like this
// now read the times.  After that, 
// call fgets() to read the remainder of the line
//

Another way to do it is to read the entire line with fgets() then use strtok() to split it into its individual fields, ignoring unwanted fields at the beginning of the line.

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

You could just use a simple while loop.

while(true)
{
   cout << "Enter a positive integer between 0 and 1000: \n";
   // rest of code goes here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>a new array that needs to allocated dynamically

Your program has not done that. And the loop on lines 15 - 19 is useless, just delete it.

First, call new to allocate an array of the same number of integers as the original array.

Next, use a for loop that counts from N (where N is the number of elements) to 0 and copy the data from the original array to the new array. Do not -- repeat DO NOT, change the value of nums variable because it must remain the same as it was after the call to new. Instead, just index into it, such as nums[i] = array1[j];

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

There is no upgrade to that compiler -- it has been dead and buried for quite some time now.

I think using mangled names is common to all linkers -- all Microsoft compilers do that too. It's beyond the scope of a linker to know the unmangled name. The mangled name is actually more useful information because it tells you exactly which of all function overloads caused the problem.

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

You need two nested loops, not just one. The first loop counts from 0 to num then the inner loop counts from 0 to the value of the outer loop, something like this

for(int i = 0; i < num; i++)
{
    for( int j = 0; j <= i; j++)
    {

    }
}
theoryforlife commented: Great for explaining why to include the function +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Will you please make up your mind about the file format. The code I posted works with the format you original posted. You can easily enhance the program to suit whatever format is the file by changing the fscanf() line to accommodate more parameters. Its not possible to read just the time that's in the middle of the line -- read evrything on the line.

And, please spell English words -- its "then" not "den". You sound like a 2-year-old when you write like that.

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

line 18 is wrong -- the array does not have 6 elements, only 5, which are numbered 0,1,2,3 and 4. There is no 5th element.

The parameters to the function in lines 5 and 27 to not agree.

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

You mean like this?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma warning(disable: 4996)

int main()
{
    int hour,minute,second;
    char ampm[4];
    FILE* fp = fopen("TextFile1.txt","r");
    if( fp == NULL)
    {
        printf("Failed to open file\n");
        return 1;
    }
    while( fscanf(fp,"%d,%d,%d,%s\n", &hour,&minute,&second,ampm) > 0)
    {
        minute = (int)(((float)minute/60.0) * 100);
        printf("%d.%d\n", hour,minute);

    }
    getchar();

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

You have to capture mouse events, which will give you the x and y coordinates of the mouse. Then just test those coordinates against the area of the window you are interested in to see if the mouse clicked inside or outside the rectangle.

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

One way to do it is to put all the code to read and write a file in a function, then call that function twice from main() with the name of the input file eacj time, something like below except you should use a different name for the function.

void foo(const char* inputfilename, const char* outputfilename)
{

}

int main()
{
   foo("data01.dat", "out1.dat");
   foo("data02.dat", "out2.dat");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>//#define CreateFile CreateFileW; // I added this line, for solved this error: error C2664: 'CreateFileW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'


DON'T DO THAT! CreateFile is declared in windows.h. Fix the error instead of trying to code around it. If you want to use char* then don't compile your program for UNICODE. To do that select Project --> Project Options (bottom of the menu list) --> Configuration Properties --> General. Then on the right side of the screen change Character Set dropdown to Not Set.

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

>>now i need to divide column of min by 60

Why? Does the minute column ever exceed 60? If not then there is no point doing that division.

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

In the while statement you posted the value of num was never changed, so all you had was an infinite loop, except for the break statement you had on line 32. The break statement cause the while loop to terminate after the first iteration.

for loops are ideal when you have to increment a counter until it reaches a specific value, such as in the project you are now working on. while loops, although they can be made to work too, are not quite as convenient as for loops.

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

ON line 19 try a for statement instead of a while statement. for(num = low; num <= high; num++) And delete the break on line 32.

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

move line 33 up to just above the } on line 31.

line 13: should use variable low here, not num.

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

Post the code you have tried. If you don't know where to start, then start here

#include <iostream>

using std::cin;
using std::cout;

int main()
{
   // code goes here
}

Write the program just a little bit at a time and you won't get overwhelmed about the program's complexity.

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

line 27 is wrong. Take a good look at it and you will see what's wrong with it.