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

You have to write a GUI program. For MS-Windows here is a tutorial

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

lines 8, 9 and 10 must be inside a function

#include <string.h>

typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };

int main()
{
    electro account[10];
    account[0].balance_due=120.52;
    strcpy(account[0].address, "Cane Gardens");

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

The most common reason for that error is including the same header file more thn once in the same *.c or *.cpp file. To prevent the problem you need to add code guards in the header file

#ifndef MYHEADER_H
#include MYHEADER_H

// declare class and other stuff here

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

What operating system? MS-Windows you can call ShellExecute() or CreateProcess(). system() can also be used but it is not recommended.

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

You should join their mailing lists to get specific and timely answers to your questions about that toolkit.

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

Writing a 32-bit program in assembly language is a very difficult task. Just converting the c code to assembly is not enough because there is a lot of work that the program does before main() is ever called, such as switching the computer from real to protected mode, building the environment and command line argument arrays, and initializing global data. So you need to learn how to do all that before you can even think of converting the c code to assembly.

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

>>and if I try snake++ it doesnt work
Because snake is not a pointer -- its a 2d array. If you want to move the data from snake[1] to snake[0] you have to move all three integers in each row.

>>What am I doing wrong?
We don't know because you need to post the code you have tried.

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

It is very difficult to get the random values in C language

Bullshit! How difficult is it to call rand() function?

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

Another approach is to use stringstream class

#include <string>
#include <sstream>
#include <iostream>

int main()
{
   std::string s = "123";
   int x;
   std::stringstream str(s);
   str >> x;
   std::cout << x << '\n';
   std::cin.get();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just gave you an example.

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

If you want to keep the data for each line separated then use a 2d array or 2d vector and declare it above that while loop that starts on line 20. float data[25][20]; is large enough to hold the data for 25 lines of code. Change the 25 to whatever you need for the data file the program is reading.

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

Yes I realize that, but you can't shuffle std::map -- the order is fixed by the class. What I proposed was just about the same thing except use cards in the range 100-152 as Hearts, 201-252 as Diamonds, etc.

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

you have to tell the compiler that ifstream and ofstream are in std namespace. There are a couple ways to do that

#include <fstream>

using std::ifstream;
using std::ofstream;

or this

#inclue <fstream>
#include <iomanip>

int main()
{
   std::ifstream fin;
   std::ofstream fout;
}
beejay321 commented: think that did the trick thanks! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't think its possible to shuffle std::map because it doesn't make any sense to do that. Seems to me what you should do to represent a deck of cards is a vector of integers, so that 101 = Ace of Hearts, 102 = 2 of hearts, 201 = ace of diamonds, 301 is ace of clubs and 401 is ace of spades. Then you could use std::ramdom_shuffle() to mix them up.

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

what's the purpose of that switch statement inside the while loop? The while loop should do nothing more than call rand() for each element of the array.

There is no point initializing the array like that when you are going to change all the elements to the value returned by rand().

>>line 27 I belive I called rand()
Oh yes, I missed that.

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

When you want to declare an array of the same size as a const string literal then don't specify the array size so that the compiler can figure out the size itself char string[] = "184553";

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

rand() returns integers, not doubles or floats, so you might as well declare setNum as an array of integers. And the code you posted does not even reference that array nor does it ever call rand()

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

call C language's strcpy() function that is prototyped in string.h.

char *error = new char[sizeof("test")];
strcpy(error,"test");
ErrorMessage(error);
delete [] error;

or just simply do this and no memory allocation is necessary

char *error = "test";
ErrorMessage(error);

or this

ErrorMessage("test");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The second line of the code you posted destroyed the pointer to the allocated memory. Pointers can not be changed after allocating memory for the very reason you discovered. When delete[] is called the value of the pointer error is no longer the same as it was then new was called.

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

The struct tm in time.h or ctime contains an integer that represents the day of the week. After getting the date from the keyboard just fill in a struct tm and pass it to mktime() to complete the structure. You must zero out all the elements of the structure before doing that.

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

Yes. Memory allocated with new must be released with delete or delete[]. That's because delete calls the destructor while free() does not.

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

but how about the minute and second? memset() does it all in one bang, faster, and less typing :)

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

Just rename the *.bak files to *.c (or whatever the original file name is). *.bak files are identical duplicates of the original. You will most likely have to exit your compiler's IDE before doing this.

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

If you just want your console program to display the data in coluns you can use setw() to set the solumn width and left or right to left or right justify the data inside the column. Example

#include <iostream>
#include <iomanip>
using std::cout;
using std::right;
using std::setw;

int main()
{
   int x = 12;
   int y = 12345;
   cout << setw(10) << right << x << setw(5) << right << y << '\n';
}

IMO I actually prefer the C way to do it because I think its easier, but you may not have this option since you are probably taking a c++ course.

int x = 12;
   int y = 12345;
   printf("%10d5d\n", x,y);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You got -1 because mktime() also considers the hours, minutes and seconds fields of the tm structure. Just use memset() to initialize the structure to all 0 then fill in the year month and day

Also -- difftime() takes two time_t objects, not pointers to two struct tm objects.

#include <iostream>
#include <iomanip>
#include <ctime>
using std::cout;
using std::cin;

int main()
{
    struct tm oldTimePtr;
memset(&oldTimePtr,0,sizeof(struct tm));
oldTimePtr.tm_year	= 2000 - 1900;
oldTimePtr.tm_mday	= 1;
time_t oldTime = mktime(&oldTimePtr);
time_t now = time(0);
cout << std::fixed << difftime(now, oldTime) << '\n';
cin.get();

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

Well, if you have a set of values and you want to select one of them at random, then use rand() as I explained previously and use that value as the index into the array. The value of N in this case will be the amount of numbers in the array. In the example you posted replace N with 3 because the array contains 3 values.

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

This will explain how to add a program to startup folder

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

rand() will return a random number. If you want to restrict it to a set of numbers between 0 and N than use the mod % operator, such as int x = rand() % N;

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

Did you compile and run that little program? If not, you should do it now so that you gain better understanding of what it does.

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

>>ohh, ok ancient the >> make read just the numbers,and not the line who begins with #(char variable) correct?

Yes, and that's why I added the getline() just before the while loop

What I posted will just read all the numbers, one at a time. You will have to add code that uses those numbers for something. I don't understand what you need to do with those numbers.

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

The kind of Master's degree would be up to you -- get one in CS if that's what you want. Microsoft probably has lots of positions for people with masters and Ph.D.

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

Look at the list of courses for each degree. The CS route requires a lot of math and is probably best if you plan to get higher degrees. The CIS is more business and programming related, with courses in business and information systems (e.g. database management).

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

The string line is correct -- its derived from std::string declared in <string> header file. You should compile and run the program yourself to see what >> does.

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

int main () {
  std::string line;
  std::ifstream is;
  float num;
  std::cout << "Enter the name of an existing text file: ";
  std::getline(std::cin, line);
  is.open (line.c_str());        // open file

  // get the first line
  std::getline(is,line);
  // how get all the rest of the numbers
  while( is >> num)
  {
     std::cout << num << '\n';
  }
  is.close();           // close file
  
  cin.get();
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 13: variable str was declared on line 3 to have only 3 characters, yet you expect someone to type up to 256???? Also, use cin.getline(), not cin.get() because getline() will allow you to enter spaces.


The syntax in the loop is incorrect. ifstrezam will make all conversions for you if you use >> operator.

float num;
std::string line;
getline(is,line); // get the first line, e.g. #S 1
while( is >> num )
{
   cout << num << '\n';
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you not read the requirements in the link you posted? They state, in one sentence, the difference between the two degrees. Choose the one that best suits your interests. You should also discuss this with your school counseler because he/she is in the best position to guide you.

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

I think you creted the wrong kind of project. My compiler said it is an unmanaged program attempting to use managed code system::Windows::Form. You should have created a CLR/C++ Windows Forms project.

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

you need to use a keyboard interrupt -- int 16h. Put it in a loop, saving each character in your own buffer, until user presses the Enter key. I would make this a separate function. You will have to check that user does not type spaces in the path because 16-bit code can not handle them.

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

If you can (e.g. if you have permissions to do so) zip up your project and attach it so that we can find out why it doesn't work for you. Delete the debug folders and other compiler-generated compile-time files such as *.obj and *.sdf

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

The out instruction outputs just one byte -- such as al. In the code you originally posted change out ax to out al

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

USERPROFILE environment variable works for me with Windows 7

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    char* p = getenv("USERPROFILE");
    if( p )
        cout << p << '\n';
    else
        cout << "USERPROFILE not found\n";
    cin.get();
}
MasterGberry commented: Perfect C++ Example :) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't, but my boss did -- he got an MBA. Was it worth it? Definitely -- opened many doors for supervisory and department head positions, not to mention more $$$.

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

>>The tiny font makes it too easy to ignore

That was my first impression too. Large, bold text -- slap them in the face with it.

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

That I didn't know -- never tried it. The last time I used MFC was in vc++ 2005, so maybe Microsoft has made more changes for .net. Did you mix CLR/C++ and MFC in the same source files?

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

>>I don't agree with ... "MFC and STL are not either or situation"

You mean you didn't know you can use STL in an MFC program.:icon_eek:

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

So sorry -- I was thinking of mov not out.

Are you writing inline code in a C program? I see you are using 0x3c8, which is C styly way or writing a hexidecimal number, instead of 03c8H, which is assembly way of writing it.

What C compiler are you using? out istruction is not valid with any 32-bit compiler but ok with 16-bit compilers such as Turbo C.

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

use a register for destination

mov ax,0
mov di,03c8H
mov word ptr [di],ax
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why is it checking to see if den == 1? What does that have to do with whether its negative or not? if(num||den < 0) That line is wrong. Should be if(num < 0 ||den < 0) . The previous if statement on lines 112-119 is meaningless.

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

tchar.h contains macros that can be used to treat standard c functions as either ascii or unicode, depending on how the program is written. If you replace strncpy() with _tscncpy() it will compile correctly either way. Read that article carefully and it will explain why, and give you an example. There are links at the bottom to other string manipulation functions.

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

If statements are better than switch in this case because switch can not be used with ranges of values. For exxample you can not say case numAvg < 60