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

You are making that a lot more difficult than it really is. As I said before -- you have to use a loop; can't be done all at one time. And you are still trying to divide by 2 -- why ????? Divison is not necessary, only multiplication. such as

sum += x * x;

Now put the above in a loop which decrements x to 0 and you have the solution to the problem.

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

Dang that looks like fun.

Yes, and you'd better have a clean pair of britches at the finish line :)

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

>>What kind of information is being added to the output and how can I get rid of it?
It adds all the code that's in procs.o and main.o. To my knowledge it doesn't add any other code like compilers for other languages do. You would have to load the bin file into a binary editor such as debug.exe in MS-Windows to find out for sure.

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

>>and in the case of ++i;
>>the loop starts from 1,

No it doesn't -- the loop still starts with 0 because the i is not incremented until after the iteration of that loop finishes.

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

most win32 api functions have two versions -- one for char* and another for wchar_t*. If you are looking at a function that uses TCHAR* then you can just safely assume char* when not compiled for UNICODE.

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

>>In my code I'm using the caret symbol for the square but it just multiply the number by 2 and not squaring it.

Of course it doesn't work for you-- that isn't what the carret symbol does in c and c++. you have to use the * symbol and simply multiply the number with itself, such as

a_squared = a * a;

>> x=x*(x^2)/2;
This isn't doing what you want to do either. That whole line is pretty useuess to your assignment. What you need is a loop that counts from 1 to x and sums up the square of each of those numbers. You can't do that in just one line of code.

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

Yes, create a library and split that procs source file into as many files as there are functions in it then compile each separately into its own *.o file then put all the *.o files into the library.

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

>>I just want to link with the procedures I use in my source and not the entire file
does that mean you don't want everything that is in procs.o? The linker will give you everything in a *.o file whethere used or not. Some linkers are however smarter and will toss out unused code. I suspect your linker is not one of them.

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

We should probably end this line of thought soon because it is very quickly becoming a religious debate thread, when it is supposed to be about democracy or dictatorship.

I agree and will probably close the thread if you don't get back on topic. :(

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

depends on the assembler, operating system and hardware in the target computer. If you are using a PC do you want the sound to come out of the sound card & speakers or out of the hardware sound speaker ? I have not attempted to do that but those are some things you will have to consider when writing your program.

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

I would suggest you forget that C code you posted and start fresh with assembly code. Sorry, but I can't help you with LC3.

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

According to nasm documentation PDF the EXTERN keyword should work. Maybe you should read it more carefully -- you do have that documentation don't you?

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

did you try to compile that? Where did you declar n do you mean a?

>>or i need to use long instead of int
Depends on your compiler and how big a nuumber you enter. you can also use a long long which is 64-bit integer that many current compilers support. But for the purpose of your assignment I suppose an int is sufficient unless your instructor stated otherwise.

Also original numbers that end in 0, wuch as 10, 20, 100, 150, etc., may not produce desired results because integers ignore leading 0s. You may have to format the output a little better.

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

maybe an example will help explain what you mean. If I enter 15 what is the expected output?

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

Huh? 1000000*1000000 is a number that is much larger than an integer can hold. Otherwise your question doesn' make much sense to me.

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

what is main.bin? I never heard of linking a *.bin file with *.o files.

>> Since I can't use nasm to make binary files with EXTERN's
And why not? Its the linker that resolves the externs, not the assembler.

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

actually that isn't even compileable C function. It needs braces around lines 3-6. And the loop starting at line 10 has several problems -- one of them is probably infinite loop at line 12 because the value of j may never get incremented.

It is also a horribly written function. Do you really want to check the same value of A about 3000 times? Since the value of i never changes during that loop it will check it AT LEAST 3,000 times, and probably a lot more times than that if the value of j never reaches 3001.

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

Wonder what the highest speed is for a runner?

Probably Michael Johnson is the fastest human alive.

Michael Johnson, who blasted the 200-metre world record at the Atlanta Olympics, ran 19.32 seconds: the first half in 10.12, the last half in 9.20.

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

use a vector instead of a simple c-style array and you won't have that problem. c++ vector class has a method that returns the current size of the array.

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

what do u mean by boost library?

Boost library

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

>>how can I make this automated to run the 10000 times without myself having to push the Y or N keys?

Replace the do loop with a for loop

for(int i = 0; i < 1000; i++)
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Why doesn't it look good?
Because why should I bother to answer here when you might already get answers elsewhere, and you might get conflicting answers at that.

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

The prototype on line 4 is incorrect. Its not the same as the actual function you coded.

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

>>why?
where did you declare hash ? I think it is probably declared in one of the boost libraries.

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

>>if(a < b && c && d && e && f && g)
Do you know what that statement does? It first checks if a < b, then if that is true it checks if c != 0, if that is also true it checks if d != 0, etc. If you want to check of a < c, and a < d ... then code it like this

if( (a < b) && (a < c) && (a < d) && (a < e) && ...)

It would probably be a little easier if you put the values in an array to that you could use loops.

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

Just how does this relate to c++? It sounds like a question for Web Development forum.

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

you mean like this?

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;


void enterData(string &todaysDate, string& firstName, string& lastName, double& amount);
void printCheck(string &todaysDate, string& firstName, string& lastName, double& amount);


int _tmain(int argc, _TCHAR* argv[])

{
    string todaysDate;
    string firstName;
    string lastName;
    double amount;
	enterData(todaysDate, firstName, lastName, amount);
	printCheck(todaysDate, firstName, lastName, amount);

	return 0;
}

void enterData(string &todaysDate, string& firstName, string& lastName, double& amount)
{


    cout << "Enter today's date: ";
	cin  >> todaysDate;
	cout << "Enter the first name: ";
	cin  >> firstName;
	cout << "Enter the last name: ";
	cin  >> lastName;
	cout << "Enter the amount: ";
	cin  >> amount;
}

void printCheck(string &todaysDate, string& firstName, string& lastName, double& amount)
{
    cout << "Zzyz Corp                                      Date: (today's date)"<<endl;
	cout << "1164 Sunrise Avenue                                        "<<endl;
	cout << "Kalispell, Montana\n                                         "<<endl;

	cout << "Pay to the order of: (string firstName lastName)      $ (amount)\n "<<endl;
	
    	

	cout << "UnderSecurity Bank                                         "<<endl;
	cout << "Missoula, MT                                               "<<endl;
	cout << "                                                ____________________"<<endl;
	cout << "                                                Authorized Signature";

	cout << endl << endl;
	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The get() function will get exactly the number of characters you specify unless it first encounters the '\n' in the file or end-of-file. Line 20 is asking for 14 characters and that's exactly what you'll get. In the example line you posted it will read "K G Johnson 45", which is probably not what you intended. I think a better way of reading that file is to first read it one character at a time until the first numeric character is encountered. This code too has a couple of minor problems but probably ok for your program.

int count = 0;
int c;
while( !isdigit((c = cin.get()) )
{
    name[i][count] = c;
    ++count;
}
name[i][count] = 0; // null-terminate the string

The size of classid is one character too small -- you have to make room for the null terminating byte.

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

some of those globals may not need to be passed to other functions. For example fstream accountInfo. Just declare it in the function in which it is used. You need to evaluate each global variable and determine which ones can be declared locally in the function in which it is used and which one you have to declare in main() then pass it by reference to the function(s) that use it.

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

That's exactly why drivers should not eat while driving. At his age he needs to give up that crap anyway to avoid getting completly clogged artires and heart attack.

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

don't know -- post your changes.

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

One thing that is good to remember is that ++i is returned by reference while i++ is returned by value.

Never heard that one before.:-O

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

>>what does it mean " if variable is not '/n'?
If the '\n' character has not been encountered -- normally signifies the end of a string in text files. '\0' indicates the end of the string in memory, assuming it is a normal c-style character array.

>>and is there any other way of writing
Could be done like this:

char str[] = "01\n";
if( strchr(str,variable) != 0)
{
    // found it
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The loop at line 123 is incorrect. Should be coded like this because eof() doesn't work the way you think it does.

while(accountInfo >> accountNumber  >> dOrC >> transaction)
{
     accountNum[count] = accountNumber;		
     dOrCArray[count] = dOrC;	        
     transactionAmount[count] = transaction;		
     count++;	
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In a word processor when you hit the <Enter> key the cursor will move one line down and all the way to the left margin. That is what the '\n' character simulates in text files. When you load a text file that contains newlines in Notepad or some other word processor you will see that behavior. Remove the newlines and everything will appear on the same line.

Exactly what is put in text files depends on the operating system -- MS-Windows adds two characters to the text file while both *nix and MAC add only one character.

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

>>Hello sorry if i hijack this thread for my own purpose
Please don't do it again. I split your thread this time for you for free :)

Line 5 is incorrect. Arrays are numbered from 0 to, but not including, the value of N. You should use the < operator, not <= operator.

To solve your problem I think just pass the second parameter by reference and let expandera_lista() increment it. That way the calling function will always have an updated copy of the size of the array.

Your function is also doing too much copying. You only have to copy once.

void expandera_lista( int *&list , int& n)
{	
	int *templist = new int[n+1];
	for(int i=0; i<n;i++)
	{
		templist[i] = list[i];
	}
	delete[] list;

	list = templist;
         ++n;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi guys,
i have one question, when i type
using namespace std;
at top of my program my compiler gives some error
especially syntax error!
my compiler is Borland C++ v.5
for example simple code:

When using the old headers with .h extension you don't use "using namespace std". Check to see if your compiler supports the new headers without an extension and use those instead. The old files are out-of-date and will cause lots of other problems if you attempt to use current coding practices.

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

>>just need to modify that to read from a file
Where ?? what line number from your original post ? Why not do it the same way you did on line 24? Same code, but use words[counter] instead of numbers[counter]

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

I think you misread, Ancient.

>> string words[6];

so there is a words[5].

You're right -- I did misread it. :icon_redface: But the comment about line 39 stands.

twomers commented: We all make mistakes :) +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 39 and 42 are wrong. The array only has 5 elements and you are attempting to access a 6th element -- won't work. And line 39 should use the loop counter variable like you did on line 30 and elsewhere.

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

Ancient, the thread you linked me to looks in the correct order?

But according to this I was the last poster, which I'm not.

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

Odd happenings just did it again, here

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

>>and what is "int" by the way. I am a little confused
its a data type. Suggestion: read your text book occasionally.

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

Really? I've always been annoyed by it being a signed long.

actually, on the two compilers I use its now a 64-bit int because int isn't big enough any more.

>>How wonderfully pointless if you want a general solution
Where did you see anyone say they wanted a "general solution"? I have never seen an os where my solution didn't work. But then I have not worked with all operating systems either, so I suppose there is a remote obscure chance that it won't work.

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

simple -- print spaces instead of '#' characers. We aren't going to actually give you the code, so try it and post your code if you have more problems/questions.

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

use the functions in time.h.

>> dont know how to store the time/date so that it can be compared with current date/time

use the time_t (normally an unsigned int) that is returned by time() for that. initialize a time_t object when starting then get it again in another variable, then simply compare the two integers. Something like this to wait for 2 minutes.

time_t t1, t2;

// initialize 
t1 = time(0);
t2 = t1 + (2*60); // want a 2 minute timer
while( t1 < t2)
{
   t1 = time();
   // do something here   
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is is really all that hard to go 130 mph when riding down a mountain sloap; now do that riding UP hill and that would be a grand achievement. ? Certainly Mr. Stoeckl diserves all the glory and attention for doing it, but I would think it could be somewhat easily achieved by other athletes.

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

After a few minutes testing it turns out to be just a little more complicated then I originally thought, Below is an example of how you need to initialize that structure. First you have to initialize it with current date/time then change the number of seconds to whatever you type in. In the example below I just hardcoded it to a value of 5255 to that mktime() will generate something other than 0 for hours, minutes and seconds.

#include <stdio.h>
#include <time.h>

int main()
{
    time_t today;
    struct tm *tm;
    today = time(0);
    tm = localtime(&today);   
    tm->tm_sec = 5255;
    tm->tm_hour = 0;
    tm->tm_min = 0;
    mktime(tm);
    printf("%02d:%02d:%02d\n", tm->tm_hour, tm->tm_min, tm->tm_sec);

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

I don't know why you are doing this the hard way with all those variables. All you need are three variables named Hours, Minutes and Seconds. To print them out with two digits each is like this:

printf("%02d:%02d:%02d\n", Hours, Minutes, Seconds);

After getting keyboard input for the seconds you have to initialize the three variables to the appropriate amount. mktime() function in time.h will help you there. First initialize a struct tm object with all 0s, then set the number of seconds user entered, then call mktime(). After that the struct tm you sent to mktime() will contain the appropriate values of hours, minutes and seconds. Finally you can code a loop to count down the number of seconds originally entered until it reaches 0.

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

I already made the suggestions in your previous thread. Read them again.