jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If there are less than 10 choices, take in the choice as a character rather than an integer. Check to make sure the character is between '1' and '9' (or '0' and '9' if you want a choice 0).

Alternatively, if a 2+ digit answer is required, take in the input as a string and check each character to see if it's a digit (using the functions in <cctype> if permitted or the approach above if it's not).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you had specified a size for the vector in main, what you did could work, but since it starts off with an unspecified size you can't index into it.

string tempstring;
while(i < MAX && in >> tempstring)
{
     str.push_back(tempstring);
     i++;
}

You should also pass the vector in by reference in order to change it within any of the functions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I ran across this http://msdn.microsoft.com/en-us/library/system.timezone(v=VS.100).aspx, I wasn't aware of its existence (particularly the IsDaylightSavingTime(DateTime) method).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

With your project open, go to the Project menu, <ProjectName> Properties, Configuration Properties, C/C++, Additional Include Directories, and add in where your header files reside.

Then also under Configuration Properties, Linker, General, Additional Library Directories, add the directory where the libraries reside.

Then Configuration Properties, Linker, Input, Additional Dependencies, add the names of the individual libraries.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is contained in the input file?

Also, your function from 55 onwards doesn't have a return type, name, or parameters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also I'm using VC++ for this.

I assume you're using a CLR/Winforms application?

Check out http://www.daniweb.com/forums/post1126074.html#post1126074. There's some extra info in there pertaining to troubleshooting that particular case, but note the classes and the setting that the OP used.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Create a DateTime object and use comparisons( <. >,==, etc.) with the current date:

DateTime vernalequinox(2011,03,21);
DateTime summersolstice(2011,06,21); //or whatever it is
if(DateTimePicker->Value >= vernalequinox && DateTimePicker->Value < summersolstice)
   MessageBox::Show("Spring!");

I'm not very familiar with CEST and CET, but I assume they change over on certain dates. You might have to change things around to match your date format, but this is the general idea.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you have more than one main()? See if you can organize these around one main, and then someone can help you figure out how to fill in the blanks.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm assuming you're using a CLR/Winforms setup.

If so, see http://www.codeproject.com/KB/IP/httpwebrequest_response.aspx for a good example (the example's in C#, so you'll have to convert the syntax, subbing :: for the C# . that indicates namespace resolution and -> for the . that indicates member variable).

HttpWebRequest is the class that is responsible for this type of action in .NET, so searching on that will get you some more resources (and of course MSDN has all of the member methods and variables delineated).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 1 of your second code listing of the first post, you still need the datatypes for str and level in the constructor definition

dragon::dragon(string str,int level) {
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're making life difficult on yourself:
Define a variable max, set it equal to the first element of the array
Step through the array, if the current element in the array is greater than max, let max be equal to that element, and set temp = index. Only change the index if you find a new max.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh, I'm so stupid. I did that, but I when I transposed the code back to the original, I mixed up a variable or two. Much thanks for solving the problem! Couldn't find a straight answer anywhere.

-A.P.

Glad to help. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edits in the last post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Substitute the line that I wrote into your code sample on line 4. If you do that, does it still give you an error? There's not that much more to it.

Not trying to be mean here, I guess I don't know what else you need to see.

BTW, if I don't mention it, someone else will, but some compilers do allow you to declare arrays with a variable size like you did, but it's an extension to the language and therefore non-standard (so probably not recommended).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not as familiar with strtok, but you should try passing in line.c_str() to it instead of the address of the first character on line 14. What you did assumes something about the implementation of the std::string which may not be true.

Either way, you seem to be getting a null pointer being passed into isValid. Output the value of inst after line 14 to see what's in there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, you would want a dynamic allocation. In C++, a fixed-size array's size must be a constant known known at compile time.

You need int * myarray = new int[sizeofarray]; Since the array is dynamically allocated with new, you need to delete it to free up the memory, delete [] myarray;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ravenous's solution is the most portable, but if the cctype functions are not allowed in your assignment, use characters in your inequalities:

char c = 'd';
if(c >= 'a' && c<='z') //use || to include the capitals c >='A' && c<='Z' etc
  etc.
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you declare a variable

float var; (or int variable; etc.)

var starts off containing garbage (whatever happens to be in memory at that spot, interpreted as a float value, which is why you get these large negative values). Initialize it to 0.0, but you'll need to indicate to the compiler that 0.0 is a float constant and not a double by writing 0.0F

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is bal equal to, prior to line 28?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use strcmp in the <cstring> header. You can't compare two C-strings using ==.

if((strcmp(string1,string2) == 0)
   cout<<"Strings are the same"<<endl;

Easier would be to use cin.get to read in a character and compare it to 'Q'

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your formatting is nice between 12 and 21, try to format the rest of your code like that, as it will be much easier to see where your mistakes are. As prvn has pointed out, you are missing a semicolon on one of your functions that you call in the switch block.

On lines 25-27 you have your function prototypes inside of main(). While the compiler may not complain, and it's not technically wrong, it's much more conventional to keep them before main.

You've done a nice job weeding out that other extraneous code from before. Keep going with it. Reference your text about functions and where to put the prototypes, definitions, and calls.

Make sure all of your function definitions begin and end with { and }

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Rather than have a global ifstream object, declare it in main() and pass it around by reference.

In your ReadLine function, what happens if your line doesn't contain any of those characters? If the function is not void, it's good practice to have a return for all possible paths through the function.

None of these problems should lead to a crash, though. It is more than likely something else. How did you determine that the function you posted was crashing the program?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where is "file" coming from in your listing in the OP?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This seems correct I got rid of the Z (14) line and added your remainder(x,y) to the cout statment at the end....I think I'm good right?

#include <iostream>
using namespace std;
 
int remainder(int x, int y)
{ 
int r;
r = x - ( x / y * y ) ;
return (r);
}
 
int main()
 
{int x , y, z;
remainder (x,y);
cout << "Enter number 1: ";
cin >> x;
cout << "Enter number 2: ";
cin >> y ;
cout <<"Your remainder is: " << remainder (x,y);
 
 
 system("PAUSE");
 return EXIT_SUCCESS;
return 0;

Yes, except line 14 isn't doing anything and is therefore not necessary.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

5/9 is an integer division, which gives the value of 0. Change one or both of them to have a decimal (5.0/9, 5/9.0, or 5.0/9.0) which will perform the calculation with doubles.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's getting a bit outdated, but this one http://www.functionx.com/vccli/index.htm has everything together in one place.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to call your function in main(). Line 14 just creates a local integer value called remainder, which bears no relation to your function. Since z is not initialized, it comes with whatever junk is in there at the time.

Your function call will look like remainder(x,y) , take a crack at figuring out where to put it, and post back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It seems like you have two programs copy/pasted here, one inside of the other. That's not going to work. See if you can arrange it into one program. Reread the section in your book on functions as to how they are prototyped, defined, and called.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Good catch, Red Goose. I think it's both things, then (if it's looking for WinMain instead of main, the project type is incorrect, but once the OP fixes the project type it's still not going to be able to find main() proper either).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've chosen the wrong kind of project. Choose "Win32 Console Application" instead of Win32 Application.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know why you would want to make your own stack class

Homework?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if(token == 1 && line->Contains("System")) You had token = 1, which assigns 1 to token, which makes it automatically true (non-zero). Also, & is a bitwise and, && is used for comparison.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

std::vector has a size() method. Use it (and subtract 1) to find the index of the last element. Access that with [].

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

JSTextBox was just an imaginary construct to prove my point. :) SkyDiploma is giving you the actual information for wxWidgets.

I think if you spend a bit more time learning about the GUI, it will become more evident to you how your code needs to be split up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I suppose I stand corrected on that particular case (and for cubed also) but, those are special characters; in general, there is not a way to direct cout to print something as an exponent.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Instead of naming your variables something doesn't make any sense, how about naming them something like totalseconds, hours, minutes, seconds.

Also, like one of the prior posters said, you have to calculate them WITHIN the program, not have the user enter the calculated value.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make your decimal to binary into a function that returns a string (with the bits going the proper direction, this is not difficult.

Chop up the address string into it's elements, place them into an array or 4 individual variables.

Use a cout statement with 4 calls to your function: cout<<"<"<<dec2bin(firstpart)<<"."<<dec2bin(secondpart)<<"."<<etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Vector has push_back and pop_back methods, so just use the end of the vector as the top of the stack. You'll have to peek at the end to get the value before you pop it, though.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

does c++ not support the tiny corner number thing

Not natively. I'm not sure if you could find a library that would do it in a console app, but it's probably not worth it either way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i know the c string has to have one extra space for \n

It needs an extra spot for '\0' the null terminus, not a newline.

If you're trying to use a std::string in a C-string context, just use the .c_str() method of it.
Assume myfunc takes a const char * as an argument

std::string strg = "test";
myfunc(strg.c_str());

If you need to do it by hand, use the .length() method of string

char * st = new char[strg.length()+1];
strcpy(st,strg.c_str());
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

MY PROF ISN'T TEACHING US SHInola. I don't know what the fudge to make out of any of this. Cool, I get what you did up there, but I don't know what to Fudging DO WITH IT. After like two hours of messing around, here's what I've got, and there are a million fudging errors, but every time I try to fix one, either 8 more come up, or they're all gone and it runs -- but the output doesn't change.

This is just one assignment, take it one step at a time. A kabillion people have gone to college in the history of time and have had professors like yours and we're all still here to talk about it.

Do what I was telling you to do before. Write one piece of it at a time, compiling it as you go.

Your functions:

void check (true, false) {
	int divides;
	if (divides=1)
		return true
		cout << divides << " " ;
}

int divides (int value) {
	int j=1;
	while (j<=value) {
		if (value%j==0) return 1;
		else return 0;
		j++ ;
	}
}

are incorrect.

Write a function divides. The function accepts two parameters: a number and a possible divisor

Right off the bat, your function "divides" only has 1 parameter. The role of the function divides(a,b) is to see if b divides into a evenly. That's all it does. Forget about check(), it's definitely not correct. If you want to have your other function return …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am GRATEFUL as that is EXACTLY the kind of ANSWER I'm looking for people for future reference...

That goes against the policies of the board that "We only give homework help to those who show effort." So that's not the answer that you're going to get.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for some reason ALL of the values in the file are read in

Apologies, there should be a break; between lines 14+15 of my last snippet there. That will stop the reading once those 5 values are read.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The file I used looks like this:

label1
1 2 3 4 5

label2
6 7 8 9 10

label3
13 14 15 16 17

And that's the output I got from the vector "13 14 15 16 17"

Trace through your code (perhaps with a debugger) and see if the values are being read in before you add them to the vector.

All else fails, strip your code down to this while loop, get it working, and build back up from there...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's my prior code with the pieces filled in:

std::ifstream ifs("readtolabel.txt");
std::vector<int> ivec;
std::string tempstring;
int tempint;
const int numbersperrow = 5;
while(std::getline(ifs,tempstring)) //let the getline drive the loop
{
   if(tempstring == "label3")
   {  //once we've read it, the ifstream has moved to the next line
	for(int i = 0;i<numbersperrow;i++)
	{
  	   ifs >> tempint;
	   ivec.push_back(tempint);
	}
   }

}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The last valid element of an array of dimension n is n-1 (line 4, you're trying to access the nth element of that particular row)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post what code you've tried and I can take a look at it.

Instead of cin, use your stream directly.

MyStream >> tempi;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's some pseudocode to move you along (even though it's not homework, I don't want to take away from all your fun)

//Get rid of all of the getlines and the while loop
std::string temp;
int tempi;
std::vector<int> vec;  //or whatever the type actually is
while(getline(MyStream,temp))
{
    if(temp == "label1")
    {
        for(from 0 to <5)
        {
            //read in a temp int using >> (no stringstream necessary)
            vec.push_back(tempi);
             
        }

    }
}

Edit: changed the data back to ints for consistency with your post

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change fee to be of type double (it will fit in a float, but live large, j/k). You'll need to change total also, otherwise whatever you add to it will be truncated.

Like Momerath said, the division of two integers will be an integer, so 4/100 = 0 (and 101/100 is 1, since there is no decimal). Change 4 to 4.0 or cast it to a double.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, the only way to get it is through the full version of VS. The Win32 API is available on the Express Editions (along with .NET).