jesseb07 64 Junior Poster

if I understand correctly, try adding this just before your return statement in "int main()"

cin.get();

that will wait for you to review the data and press enter before exiting the program. As it is now as soon as it's done with all of it's tasks, it closes instantly.

~J

jesseb07 64 Junior Poster

your boolean logic is ill-formed inside of your if statements, instead of

if(a==R||r)
//etc.

it should be

if((a == R) || (a == r))
//etc.

how your first logic reads is "if a equals R or if r".
how I think you wanted your logic to read is "if a equals R or if a equals r"

but yes, as wildgoose has mentioned also: r, R, g, G, y, Y will all be the compiler default value of int, they are uninitialized thus making them unsafe for comparisons.

hope that's helpful

~J

jesseb07 64 Junior Poster

looks like there's a couple things, I don't think that would even compile: comparing a map<int, vector<int> >::iterator to an int inside your loop doesn't seem safe to me. As well as not declaring the map type for your iterator.

anyway, see if this is a good starting point:

map<int, vector<int> > my_map; //I assume these are global or in a class, as you had it
map<int, vector<int> >::iterator it;

void erase(int num)
{
    for(it = my_map.begin(); it != my_map.end(); it++)
    {
        if((*it).first == num)
        {
            my_map.erase(it);
            break;
        }
    }
}

I think that's what you were going for, hope that's helpful

~J

jesseb07 64 Junior Poster

So I changed my code and tried your way to no avail... :/

#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(void)
{
   // with addition of buffers for 3x3 square mask
   // 8x8 original image is now 10x10
   int [][10] imageSquare =                            
   { 
   	{4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
   	{4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
   	{4, 4, 4, 4,48, 4, 4, 4, 4, 4},
   	{4, 4, 4,64,64,64,64, 4, 4, 4},
	{4, 4,17,64,64,96,64, 4, 4, 4},
	{4, 4, 4,64,85,64,64, 8, 4, 4},
	{4, 4, 4,64,64,64,64, 4, 4, 4},
	{4, 4,56, 4, 4,23, 4, 4, 4, 4},
	{4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
	{4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
   };
}

This still gives the same error of comp.cpp:12: error: expected unqualified-id before '[' token.

I mean, it says it's expecting some kind of id before [ which I obviously don't have. But again, I have absolutely no idea what I am missing.

ironically enough, you missed the entire point of my post, change "int[][10] imageSquare" to "int imageSquare[][10]" and your compiler error will go away

jesseb07 64 Junior Poster

do you mean if you don't explicitly create a constructor in your class, or are you referring to constructor overloading?

if it's that you don't explicitly create your own, here's what happens

#include <iostream> //feel free to give this a test to see for yourself, it should compile ok
class Test
{
    public:
        int x;
};

int main()
{
    Test testObject;
    std::cout << testObject.x << std::endl; //this will print the compiler default for an int
    return 0;
}

the object will be created with the default values for all fields.

If you are asking about constructor overloading, it's just like function overloading: the compiler looks at the function signature to choose it for you.

for more info, maybe check out: http://www.cplusplus.com/doc/tutorial/classes/

Hope that's helpful

~J

jesseb07 64 Junior Poster

2 things:
first, arrays are declared like this:

int array[5];
int array2[] = {1, 2, 3, 4, 5};

not like this:

int[5] array;
int[] array2 = {1, 2, 3, 4, 5};

secondly, when dealing with multidimensional arrays, unfortunately you can't do

int array[][] = {{1, 2}, {3, 4}, {5, 6}};

you have to do

int array[][2] = {{1, 2}, {3, 4}, {5, 6}};

you can only leave the first dimension of an array up to the compiler (I'm going off of g++, it COULD be different for other compilers).

since you were googling for an answer, maybe check this out as well:
http://www.cplusplus.com/doc/tutorial/arrays/

Hope that's helpful

~J

jesseb07 64 Junior Poster

WHAT 12 ?
well 12 is suppose to be of the array for DOB[12].

What n? and the n is to save the crn [n] so that it can matched the DOB [12].

well, that should give you several problems considering you declared DOB to be an array of size 10

int DOB [10]= {1980,1981,1982,1983,1984,1985,1986,1987,1988,1989};

DOB[12] would put you past the end of the array, returning who-knows-what when you try to reference it.

jesseb07 64 Junior Poster

the syntax for a do-while loop is this:

do
{
     //stuff to loop through
}
while(conditions); //note the colon

and maybe consider changing your 'switch' statement to a series of if-else since there's more than 1 or 2 lines of code for each option. I think that's more of a style issue.

Edit: one more thing I noticed

you have your 'for(;;)' but once you run through your do-while loop, you have a break, exiting the for loop. So you only run through the for loop once, maybe look at why you have a break there

Hope that's helpful

jesseb07 64 Junior Poster

your problem is in how you are compiling it. You need to compile each .cpp file separately into objects and then link them all together at the end. Give this a try (my g++ flags are a bit rusty, but I think they're right)

g++ -c time1.cpp -o time1.o //compile into an object
g++ -c time.cpp -o time.o //compile into an object
g++ time1.o time.o -o time //link objects together

Hope that helps

~J

jesseb07 64 Junior Poster

Well I don't need to return any values other than the bonus amount. So would I make my displayBonus function like

void displayBonus(double &bonus)

?

no, since you are not altering 'bonus' in displayBonus, you don't need to pass it by reference, you also don't need to return it, you're only displaying what it is.

This looked like a good explanation of what passing by reference means if you are a bit confused as to what is actually going on:
http://www.tech-recipes.com/rx/1232/c-pointers-pass-by-value-pass-by-reference/

give that a look over and then you can see when it's needed and when it's not.

~J

jesseb07 64 Junior Poster

global variables ARE a bad idea, which is why it's not the only way to accomplish this with a void function. Try passing things by reference:

void getSales(double &sales); //try this instead
//other functions
 
int main()
{
       //declare constant and variables
       const double RATE = .1;
       double sales = 0.0;
       double bonus = 0.0;
 
       getSales(sales);

       //sales is now whatever you calculated it to be from inside getSales

       //blah blah blah
}

make sure you change your function appropriately (should be simple) and also implement wildgoose's suggestion of a do-while loop. Hope that's helpful

~J

jesseb07 64 Junior Poster

I personally generally use an EVENT_TABLE if I have a large number of events for a class ( > 5 or so), but if I only have 1 or 2 I generally use Connect (or I have a complicated gui, lots of enabling/disabling etc). I've just found it to look cleaner: prevents a ridiculous amount of event tables but if there's a ton of events it's easier to keep them straight in an event table. That's my preference, there are some different things that can be done with connect so it's not a straight substitute either way, but if you want something more than that, here's explaining the subtle differences:

http://wxwidgets.blogspot.com/2007/01/in-praise-of-connect.html

Also, another interesting bit of info is that in my wxwidgets book, written by the creators, all of their examples (that I've seen) use event tables. It's possible that there's performance differences (significant I mean) since event tables are static routing and connect is dynamic but I have yet to see anything definitive so I'm going by what I like :)

hope that's helpful

~J

Nick Evan commented: Good post +18
jesseb07 64 Junior Poster

instead of using the ascii codes which would get a bit more complicated when you add numbers because of the disconnect between the codes (since numbers are 48-57 and letters 97-122), why don't you try something like the following as a starting point:

string random_letter(int length) 
{
     const string values = "abcdefghijklmnopqrstuvwxyz";
     const int valuesSize = 26;
     string s;

     for (int i = 0; i < length; i++) 
     {
          s += values[rand() % valuesSize];
     }

     return s;
}

then you can add whatever characters you want (numbers), just a suggestion.

~J

jesseb07 64 Junior Poster

check my last post, looks like you overlooked it.....

Here are things to help us solve issues with people's programs:
- Sample input/output (none provided)
- Desired input/output (none provided)
- Compiler output (none provided)

There is no reason that I should have to compile your code to find out what the compiler errors are...

I agree, essentially it's good practice (in my opinion) to make it as convenient as possible to help you. Please post the actual and desired input/output.

jesseb07 64 Junior Poster

I see a problem from how the program should be running (although desired results would be nice to know...) it's in your do-while loop
Here's Dave's wonderfully simplified code:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
int main ()
{
	int num;
	do
	{
		cout<< "something" <<endl;
		cin>>num;
		cout<<endl;
		num++
	
	}while(num!=0);

	switch (num)
	{

		case (0):
			cout << "End of program"<<endl;
		case (1):
			cout<<"something else"<<endl; 
			break;
		default:
			cout<<"Invalid number. Please choose again.";
			break;	
	}
	return 0;
}

you will notice that the only value of num that will ever get to the switch is 0. Simple fix, move the do-while to include the switch statement:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;
int main ()
{
	int num;
	do
	{
		cout<< "something" <<endl;
		cin>>num;
		cout<<endl;	

	        switch (num)
	        {

		        case (0):
			        cout << "End of program"<<endl;
                                break;
		        case (1):
			        cout<<"something else"<<endl; 
			        break;
		        default:
			        cout<<"Invalid number. Please choose again.";
			        break;	
	        }
        }
        while(num != 0);

	return 0;
}

see if that's what you're looking to do.

jesseb07 64 Junior Poster

so, does that solve your problem or (since you never said what the problem was) is there more?

jesseb07 64 Junior Poster

everyone gets heckled a bit from time to time, don't let it bother you.

Now, per your request regarding the program.

I will try to convince you that it is a bad idea for a beginner.

1st. 6month old babies don't learn to drive on the autobahn (take the analogy)
2nd. Notice EVERY tutorial on "Your very first [insert language here] script" is a "Hello World" and not Halo 3, there is a definite reason for that

You've gotta start somewhere, it's true, but try crawling (Hello World) before flying. Should you embark on this project anyway, you will find that you will not learn much (if anything) because without a good foundation in the basics and even intermediate concepts, it will be baffling.

Take the advice of someone who's been coding for 7 years that this is too much for you.

I can make an awful lot of very nice things on paper (like an anti-gravity machine for example), but that's essentially saying the same thing as "Hey I drew a picture!" the implementation is always the tricky part.

~J

Salem commented: Well said +20
jesseb07 64 Junior Poster

please post the relevant section of code

jesseb07 64 Junior Poster

Hey, looking at your program looks like you have a few simple errors, logic and otherwise.

#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;



int main()
{
int n;


cout << "Please enter a integer  ";
cin >> n;


for (int i = n; i <= 25; n++)
{
cout << "*" ;
}


cout << endl;


return 0;
}

#include "stdafx.h"

should be

#include <stdafx.h>

except when I ran it through my compiler it had no idea what that was, so when I removed it, it didn't affect functionality, so I'm not familiar with that one.

in your for loop, try this:

for (int i = 1; i <= n; i++)
{
cout << "*" ;
}

the reason for this is that the way you had it set up is that it would always display 25-n "*"'s which as I gather is not what you want. you also had n incrementing instead of the looping variable which it should have been. Chances are your program just kept on spitting out "*"'s indefinitely since the for loop would never be satisfied.

With that code modified it compiled and ran fine for me, let me know if it works for you.

Hope it helps!

~J