twomers 408 Posting Virtuoso

I haven't really worked on many extravagant projects. Nurtured some pet projects over time... favourite (which doesn't work anymore!), was a program that sent SMS text messages via an online interface. Very convenient, but the website has changed how it works (potentially techniner's work ;)). I haven't put much work into remedying the problem, but man am I frustrated.
DSPs are fun, alright, Dave. Can be a head-wrecker from time to time though!

>> lazer printer
Laser printer? American spelling? But that wouldn't really make sense... :-/

Dave Sinkula commented: "DSPs are fun, alright, Dave. Can be a head-wrecker from time to time though!" -- True dat. +13
twomers 408 Posting Virtuoso

Probably. That's the way I do it. You can also, if you wish, look into LoadLibrary (capitalisation?).

twomers 408 Posting Virtuoso
#include <my_dll.h>
#pragma comment( lib, "my_dll.lib" )

int main() {
  my_dll_function();
  return 0;
}

Should work with your IDE.

twomers 408 Posting Virtuoso

Well, as nice as command != ('A' || 'B') looks it doesn't work like that. if( command != 'A' || command != 'B' ) is what you're looking for, but to be honest a straight out else should do -- it's proven to neither be an 'A' or 'B'.

Not sure if that's your problem now. Don't have linux.

twomers 408 Posting Virtuoso

>> House isn't a sitcom.
Tru dat. Saw sitcom, thought TV and said House. 'Pollogies to my peers.

twomers 408 Posting Virtuoso

House.

twomers 408 Posting Virtuoso

>> Could anybody help me with the code please?
Not unless you show some work.
But it's not that hard. There are two problems to overcome -- 1) filling the array 2) reading values from a file. Once you have those two done there's really no problem. Show attempts on both.

twomers 408 Posting Virtuoso

I really don't know what you mean. Do you want to save integers to file? Binder?

twomers 408 Posting Virtuoso

I'm pretty sure you're making that up, or at least mistaking it.
Do you have a cin.ignore() or cin.get() or something before the function is called?

Also, you should use std::string to read in the file and getline(). It makes it much easier... Also work with lines rather than characters. You could open the file in binary mode and read the whole thing at once if you wanted too... but I can never remember off the top of my head how to do that ;)

#include <string>

// ...

void read_file( void ) {
  std::string line, file, f_name;

  std::cout<< "What's the filename: ";
  std::cin >> f_name;

  temp.open( (f_name+".mth").c_str() ,ios::in|ios::nocreate);

  while ( std::getline( temp, line ) )
    file += line + "\n";

  std::cout<< file;
}

By the way... just ran your code there and it doesn't getch() before reading the file for me, so it must be something in your main() code before the function is called.

twomers 408 Posting Virtuoso

Well, by playing with the code from the link I got this:

#include<windows.h>
#include<stdio.h>
#include<conio.h>

#pragma comment(lib, "Winmm.lib")

//command, note, velocity
#define MAKE_MSG(X, Y, Z) (X + (Y<<8) + (Z<<16))
#define NOTE_ON 0x90
#define NOTE_OFF 0x80

int main(void){
  HMIDIOUT x;
  if(midiOutOpen(&x,-1,NULL,NULL,CALLBACK_NULL)!=MMSYSERR_NOERROR ){
    printf("ERRORS ahoy\n");
  }

  midiOutShortMsg(x, MAKE_MSG(NOTE_ON, 62, 65));

  _getch();
  return 0;
}

I don't know if your code should play anything.

twomers 408 Posting Virtuoso

One thing you could do is map out a directory. The structure could have the name of the directory, an array of sub-directories (which would possibly be a pointer to a new instance of the structure itself), and an array of file names as members. You can search through it for a file, directory etc. Sort by date, size, name, etc.

twomers 408 Posting Virtuoso

I'm fairly sure I am... I mean no Irish living in Ireland do it. The ones living away clearly have to go the extra mile to boast their patriotism, I guess. Either that or it's cheap... is it subsidised?

twomers 408 Posting Virtuoso

>> green beer
And you started off so well with you talk of the stew, albeit a weak stew (:)), green beer... not an Irish thing. Frankly it looks not nice, IMO.

twomers 408 Posting Virtuoso

Irish stew, mmm.
Traditionally it's alcoholic, heh.

twomers 408 Posting Virtuoso

Did you even look at the link I sent? Gah!

http://www.cplusplus.com/reference/clibrary/cstdio/fgets.html

Salem commented: You can lead a horse to water, but you can't make him think! +11
twomers 408 Posting Virtuoso

Do you want to print the contents to your screen or to the file? The way you opened the file there was for writing, that's what the w stands for. I was under the impression that you wanted to read the file. Use r for that. Look into fgets, or fscanf (if memory serves). http://www.cplusplus.com/reference/clibrary/cstdio/fgets.html

twomers 408 Posting Virtuoso

Simple file io. First hit on google - http://www.cprogramming.com/tutorial/cfileio.html. All you need to do is point the file pointer to your desktop. You can hard code that if you want. Then open the file for reading (see link), and print its contents to screen.

twomers 408 Posting Virtuoso

Wow. We give out about people not giving us enough code all the time ... but all the code... one would think it's a good thing...
However, I, for one, am not going to look at any of them. I think it's generally said to post the smallest segment of code which illustrates the problem. Please do so. You'll get more responses in my opinion.

iamthwee commented: I would agree with that +13
twomers 408 Posting Virtuoso

How'd DOS (or the lack there of), come into the discussion of the end of the world!?

twomers 408 Posting Virtuoso

Take a look at this:

int main() {
  int numbers[4][4] = { { 0, 1, 2, 3 }, 
                        { 4, 5, 6, 7 }, 
                        { 0, 9, 8, 7 }, 
                        { 6, 5, 4, 3 } };
  int (*p)[4] = numbers;

  (*p)[0] = 42;
  p++;
  (*p)[3] = 63;

  for ( int y=0, x; y<4; y++ ) {
    for ( x=0; x<4; x++ )
      std::cout<< numbers[y][x] << " ";
    std::cout<< "\n";
  }

  return 0;
}
twomers 408 Posting Virtuoso

You can point it to the first y position.

int *p = numbers[0];

Or whichever one you want.

twomers 408 Posting Virtuoso

Put (int*) before the error area.
Or look up some C++ casts.

twomers 408 Posting Virtuoso

Thanks for the explanation, Ptolemy. I hadn't heard of them before. Sounds like fun to implement. I can only assume that one uses the 'boundrary conditions' (ie start and end nodes where previous and next respectively will be NULL), to extract the next and previous addresses of all the other elements. Would be a bit more painful if it was a completely cyclic list though.

I glossed over your explanation, sorry. I assumed you were explaining XOR to me :) Makes sense.

twomers 408 Posting Virtuoso

First things first. Do you know how to write a regular linked list?

twomers 408 Posting Virtuoso

Please elaborate. A linked list I can understand. Exclusive or I can understanc. Doing a linked list using XOR ... I'm not certain what you mean.

twomers 408 Posting Virtuoso

Yes. One thing you could do is create a running-sum of numbers and ask the user at the start how many numbers they want to insert, then loop that many times. After it's all looped divide by the number of iterations which were inputted.
Alternatively you could read the numbers in as strings, stringstream to a number (you familiar with stringstreams?), and keep the same running-sum as before and after loopin' divide by the number of iterations.
Or you could read in integers until someone enters an invalid value ... like a character where you require an integer.

>> If I input a letter instead of nummber how can I make it so program says that it is invalid input value or something like that ?

#include <ios>
#include <iostream>
#include <limits>

int main( void ) {
  /* ... */  

  int num;

   while ( !(std::cin>>num) ) { // If the inputting failed
     std::cout<< "You didn't enter an int!\n";
     std::cin.clear(); // Make sure to clear the stream's errors
     std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); // and remove the offending characters.
   }

  // num fine here.

  return 0;
}
twomers 408 Posting Virtuoso

>> decision == "B" || "b"
That isn't what you think... what you want is:

decision == "b" || decision == "B" or you could do some kind of toupper() usage. That applies to all the comparisons too.

twomers 408 Posting Virtuoso

Where do all these lies about TV and the Internet come from?

twomers 408 Posting Virtuoso

Sorry! My bad:

for (k =0; k < rows; k++) {
      for (m =0; m < cols; m++)
        cout<< image[k][m];
  cout<< "\n";
}

What I posted earlier just throws everything on one line but this should put a new like after every row. stupid mistake of mine. Sorry.

twomers 408 Posting Virtuoso
for (k =0; k < rows; k++)
      for (m =0; m < cols; m++)
        cout<< image[k][m];
twomers 408 Posting Virtuoso

>> How else would sum up the total of the number the user entered?

#include <iostream>
#include <iterator>
#include <numeric>

int main()
{
   std::cout << std::accumulate(std::istream_iterator<int>(std::cin),
                                std::istream_iterator<int>(),
                                0);
   return 0;
}

Only kidding :) Ignore that!!

Now.
>> for (num=1; maxNum=1; input++)
Do you know the proper format for a for loop?
for ( INIT; CONDITION; OPERATION )
so you want for num=0; num<maxNum; num++ )

Also, a good habit to get into is to initialise your variables to a certain value. So:

int num = 0;
int total = 0;

as they are not guranteed to be defaulted to one. If you look at the variabel total it's not set to any value so if you add something to it... the sum may not be correct.

>> maxNum++;
Why did you do that?

twomers 408 Posting Virtuoso

>> int image [ROW_SIZE][COL_SIZE];
OK. You want to display the image as characters ... do you need to keep it in memory? If you do you can either change the type of the image to a character array. It'll read in all the numbers as single characters. Then, once it's all read in, you can convert a '0' to a '-' or whatever, hece using the same variable.
Alternatively you could just create a second array of the same size...

It might be worth dynamically allocating enough memory for the image at runtime ... You familiar with new/delete?

twomers 408 Posting Virtuoso

The source file itself got deleted? I'm disinclined to believe it could be the compiler ... but what compiler are you using? You certain it's gone? And that it's just not where you thought it should be. Have you searched for it? (as in the OS searches, not you)

twomers 408 Posting Virtuoso

Yeah... I can see that effecting the earth more than fempto powered fields.

twomers 408 Posting Virtuoso
void Student::input ( )
{
    cout << "This program reads a student name and the number and name of the classes.\n" ;

    cout << "Enter the student name:  " << flush ;
    getline ( cin , name , '\n' ) ;

    cout << "Enter the number of classes:  " << flush ;
    cin >> numClass ;

    delete []classList;
    classList = new string[numClass];
    cin.ignore();
 
    cout << "Enter " << numClass << " classes, each followed by pressing 'Enter':\n" ;
    for ( int i = 0 ; i < numClass ; i++ )
        getline( cin , classList [ i ] ) ;
}

I highlighted the changes in red. You have to delete what's there and re-allocate it so that you don't mess it up! And the ignore goes after the >> but before the getline()

This program reads a student name and the number and name of the classes
Enter the student name: 5
Enter the number of classes: 5
Enter 5 classes, each followed by pressing 'Enter':
d
d
d
d
d
Outputting student data for: 5
1. d
2. d
3. d
4. d
5. d
Outputting student data for: Caleb
1. Cisco
2. C++
3. Economics
4. NV.NET
5. C#

Duki commented: Excellent help. +4
twomers 408 Posting Virtuoso

Your other problem use cin.ignore();

Mixing up getline() and cin>> and getline() again will store '\n''s in the the buffer which getline() will recognise and hence pass out.

twomers 408 Posting Virtuoso

Also you can put the initialisation in the initialisation list:

Student::Student ( string sName , int numC , string cList[ ] ) : name ( sName ) , numClass ( numC ), classList( new string [numClass] )
{
    for ( int i = 0 ; i < numClass ; i++ )
        classList[ i ] = cList[ i ] ;
}

Might as well use it when you can.

twomers 408 Posting Virtuoso
Student::Student ( string sName , int numC , string cList[ ] ) : name ( sName ) , numClass ( numC )
{
    classList = new string [numClass ] ;
    for ( int i = 0 ; i < numClass ; i++ )
        classList[ i ] = cList[ i ] ;
}

You must specify the size of the array you're allocating. Can'e new[]!

twomers 408 Posting Virtuoso

>> Some astronomers say that it might trigger a shift of the earth's magnetic poles,

OK. Fields decay with 1/r^2 ... so ... 1/light-squared-years is very very small.

twomers 408 Posting Virtuoso

String is part of the standard library so either:

using std::string ;

or std:: all strings.

twomers 408 Posting Virtuoso

>> is there a better way to do it?

Run this:

#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int main( )  {
  string line, word;
  ifstream in;


// ONE WAY OF READINF FROM A FILE
  in.open( "FILENAME.TXT" );

  if ( in ) // If stream opened successfully
    while ( std::getline( in, line ) )
      cout<< line << "\n";
  in.close();


// OTHER WAY OF READING FROM FILE
  in.open( "FILENAME.TXT" );

  if ( in )
    while ( in >> word )
      cout<< word << " ";
  in.close();

  return 0;

}

And see if you can understand it. THe first way reads a file line by line and the other way does it word by word.

twomers 408 Posting Virtuoso

It's the latter, I think. Look at vectors later on. In short they're expandable arrays which aren't set in size on build.

He wants to store the whole file, I believe.

You know where you fin.open and fout.open. Only deal with one aspect of the proess at a time. First open the file and store the contents. Then close it and open the out file and write the contents you have stored by reading from the first file. Then close the output file.

So change:

ifstream fin;
        ofstream fout;
        fout.open(File);
        fin.open(File);
        while (!fin.eof()){
            fin.getline(line[counter], 125);
            counter++;
        }
        for(counter=0; counter<10; counter++){        
            cout<<line[counter]<<endl;
        }
        fin.close();

to

ifstream fin;
                // READ THE INPUT FILE
                fin.close()


        fout.open(File);
                // WRITE THE OUTPUT FILE
        fout.close();
twomers 408 Posting Virtuoso

OK. First thing first. You're using C++ so you should think about using std::string rather than statically sized character arrays. Benefits - dynamically resized, memory automatically managed, public methods, easy to use operators (like equality). Downsides - you're going to have to learn them.
Especially since you "#include <string>".

Also if you're going by words you might as well do something like:

// Prep work like setting up input stream, testing it etc.
std::string str;
while( in >> str ) {
  std::cout<< "This is a word: " << str << "\n";
  // etc...
}

Note or warning - that stops at whitespace. Not at punctuation so you're going to have to think about that.

I don't think you're going to be able to open a stream to both write and read a file at the same time. Open a stream. Read the contents. Close the stream. Open another one. Output the contents. Close that stream then.

Something else to consider is using a vector to store all the stuff you read rather than a 2D array.

twomers 408 Posting Virtuoso

Did you just add some getlines? It's hard to see what you did differently. Could you maybe highlight it in your code?

twomers 408 Posting Virtuoso

Cause
if ((temp * temp) == j)

returns false?

twomers 408 Posting Virtuoso

Well you'll have to initialise all of the variables.

>> if (userGuess == Black || black)
That's not (or rather mightn't), work as you would expect: it'll do the || ing first and then the == (or the other way around, I can't remember), so what you want to do is probably:

if (userGuess==Black || userGuess==black)

Same goes for the other two if's.


You know. I think what you're trying to do is use strings... something like this might work better:

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

int main( void ) {
  //Define variables
  std::string userGuess;
  int EuserGuess, wager;


  // Welcome user and display odds
  cout << "Here are your odds:\n\n";
  cout << " 1 to 1 | Black (Odd Numbers)\n";
  cout << " 1 to 1 | Red (Even Numbers)\n";
  cout << "35 to 1 | Exact Guess..n" << endl;

  //Ask for user input
  cout << "How would you like to place your bet?\n";
  cout << "Black, Red, or Exact: ";
  cin >> userGuess;

  if (userGuess == "black")
    userGuess = "odd";
  else if (userGuess == "red")
    userGuess = "even";
  else if (userGuess == "exact" ) {
    cout << "What number would you like you place your bet(1-36)?";
    cin >> EuserGuess;
  } else {
    cout<< "Error! Exiting";
    return 1;
  }

  cout << "How much would you like to wager?\n";
  cout << "$ ";
  cin >> wager;

  cout << "\n\n\nYou have chosen to wager " << …
twomers 408 Posting Virtuoso

OK. Well for section one you should look into the division and remainder operators and loop ... Could be a long loop so think about it and see if there are any tricks you can use.

Section 2 is very similar.

Look at this code:

int main( void ) {
  int num;

  std::cout<< "Enter a number: ";
  std::cin >> num;

  while ( num ) {
    std::cout<< num%10 << " ";
    num /= 10;
  }

  return 0;
}
twomers 408 Posting Virtuoso

>> there is no difference between the people who sacrifce a goat to their god of the sky and a christian who pray to christ to protect the plane.

I think you're somewhat biased here, Wolf. There are four cases you must consider for this arguement (of only god to whom they sacrificed a goat and the Christians'. Obviously the options scale up and up and up if you wish to introduce more).

I) There are no gods
II) There is one (lets say the god of the sky)
III) There is one (lets say the Christians' God)
IV) There are two (in case II, and III above).

If you wish to argue sensibly you have to be objective about your beliefs. You mentioned that your beliefs are of case I above. In that case you are right. Sacrifice and prayer are useless.
If II exists and the god of the sky demands sacrifice then sacrificing goats would be more effective than prayer.
If III exists then the prayer should have more weight than a goat.
And if the case is IV then it depends I guess.
And you cannot use your beliefs as a bases on which to judge every eventuality. Just suppose for one instance that you are wrong and that either case II or III is correct... Anyway.

God-threads always go bad so I'm going to leave this here.

twomers 408 Posting Virtuoso

>> you are wrong. not less means more.
Well if that's how you view the wording then I am wrong. But it is not what I meant.

"Aught not be less". Doesn't have to be less. Could me more. Could be the same. Still could be less.

It was first suggested that prayer should be less effective than sacrifice. So I put forward the opinion prayer doesn't have to be less effective than sacrifice if the god to whom you pray doesn't require sacrifice.

twomers 408 Posting Virtuoso

No. That's not what I said.
While it is what I believe (I don't see any reason to deny that), my post said: "prayer aught not be less effective than a sacrifice", from the arguement I put forward in the same. I did not say "my religion is right", or anything suggesting my beliefs being the only correct ones. I didn't even say anything about my beliefs.

What I did was acknowledge that my religion and beliefs may not be right (or rather that others believe in other beliefs). I said "aught not be less effective", not "the only way".

Wolf, I wasn't attacking your athesism and I would appreciate it if you wouldn't put words in my mouth.