jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Within your block

for (i = 0; i < 6; ++i )
{
          if ( students >> studentid[i] >> fname[i] >> lname[i] >> Q1[i] >> Q2[i] >> Q3[i] >> MidTerm[i] >> Q4[i] >> Q5[i] >> Q6[i] >> Final[i])

you have cout << all your stuff
CalculateAverage() //prints out one average (no line break or spaces)
out << all your stuff //sends to file silently
CalculateAverage() //prints out the second avg

So bring back your average function that returns a double, tack that on the end of your << chain (for both cout and out, e.g cout << var1<<var2<< Final<<CalculateAverage()<<endl;) and you'll have your average once and getting sent to the right spots.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hi tasky23,

You need a bit more to open the file. Declaring an instance of ifstream is the correct start but it should read:

ifstream infile2;
//then to open the file.
infile2.open("file.txt",ios::in);

See: http://www.cplusplus.com/reference/iostream/ifstream/ifstream/ his notation is a shortcut.

@OP: I think the brevity of your post is excellent (though the title could use some dressing up ;) ) but in this case people might need a bit more code to get at the heart of the problem more quickly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I should have tested it further, apologies. I thought I had it but it kept crashing after the word was entered

It's not exactly what you want but it requires an enter press after "lolsup" is entered

private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
                if (textBox1.Text.Contains("lolsup"))
                {

                    textBox1.Text += "\r\nClient: Hey";
                    textBox1.SelectionStart = textBox1.Text.Length;
                    textBox1.ScrollToCaret();
                }

        }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code-tags the next time...

double rad;
double circum;
double ar;
double radius1;
double circumfrence1;
const double pi=3.141616;
cout << "This Program Finds The Area, Radius and Circumfrence of a circle!" << endl;
cout << "Please where the center of the circle is, please enter two numbers " << endl;
cin >>x1;
cin >>y1;
cout << "Please enter a point of the circle, please enter two numbers " << endl;
cin >> x2;
cin >> y2;
radius1 = radius(x2,x1,y2,y1);
cout << "The Radius of the Circle is:" << rad << endl;

Where is rad written to between these points in your code?
Reread the section in your text on variable scope. There's no relationship between your rad variable in the function and the one in main. Radius1 has what you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for (int i = 0;i<3;i++)
	{	
                cout <<names[i][0]<<" "<<names[i][1]<<" ";
		for(int j = 0;j<6;j++)
		{
			cout <<scores[i][j]<<" ";
		}
		cout <<endl;
	}

You can't use << with the array, unfortunately.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just take away the <=10 and substitute in <10, going less than or equal to will overstep your array.

Also, you can accomplish the first part with just the loop variables (no need for n) ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's a bit too much hard coding for me but how about

int strcnt = 0;
	for (int i=0;i<3;i++)
	{
		fin>>names[strcnt][0];
		fin>>names[strcnt][1];
		strcnt++;
                
                //inner loop etc.
      }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I meant to ask before but didn't, why is names a 2D array? I'd just make it 1D and dump that second for loop for(int col=0; col<3; col++) .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

put a do-while loop around the whole thing, prompting the user at the end

string response;
do
{
      //your code here
      response = Console.ReadLine();
}(while response != "Yes" && response !="yes") ;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

use fin >> and since you know the order of the line (1 string, 6 numbers, 1 string, 6 numbers, etc.) make a nested for loop (rows and then columns) to put them in their proper variables.

P.S. It doesn't matter too much, but if you are going to do that color thing at least put it back to the way it was or do away with it altogether.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Shouldn't line 32 just be p = i+p; (or p+=i; )? That way you put your interest into principal and iterate again.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Maybe I'm missing something but hashArray has nothing in it. I'm not sure why you are treating your numbers as chars?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
char c = 'A';
char d = c ^ 0x20;  //'a'
char e = d ^ 0x20; //'A' again

The regular OR only works in one direction(from upper to lower)
also you could just add or subtract 32 from the char if it's easier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to #include <algorithm> and call: sort (myvector.begin(), myvector.end()); (see http://www.cplusplus.com/reference/algorithm/sort/ for a reference)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

.NET has this http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx but I don't know if you wanted win32/unmanaged (you'd need the HighResolution on -- I'm trying to find the order or magnitude of the smallest timestep -- looks like it's 100 nano)

Elapsed = 00:00:00.0052618

Though I'm sure the figure it gives comes with a little bit of wiggle room as most things that rely on ms level measurements in Windows do (due to scheduling and interrupts and many other things that I'm either rusty on or ignorant of).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try yourtextbox.Text +="Your new line of text here \r\n"; That gives you a carriage return and newline, and do this for every line that you add.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The {0,20} is a placeholder and format specifier for a variable that was in the other example you had. For example:

int i = 1;
char a = 'a';
double pi = 3.14159;
Console.WriteLine("{0} {1} {2}",i,a,pi);

prints out: 1 a 3.14145 (each placeholder is replaced by the value)

So for your application, you can just simply make it one string: Console.WriteLine("Year Rate Amount Interest New Amount"); or if you want the year in there Console.WriteLine("Year {0} Rate Amount Interest New Amount",year);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I know it's semi-possible to do this by hand (and I'm sure everyone's always looking for an excuse to overhaul the system, not), but a system where you could cite other threads (say max 5) and "continue" them without having to stomp on the initial thread. That way there are prune points if a thread gets "contaminated."

It's hard to tell where to draw the line with bump-type posts. It seems like 8 times out of 10 they are totally useless, 1 time out of 10 it's borderline (someone's put something together for a request that's long passed, someone has an opinion on the original post) and 1 time it's a clear and cogent addition. I've gotta believe that admins and mods give more than 110% already so asking them to make a judgement call in situations like this might be unreasonable.

I haven't been here very long (not long enough to have seen that notification before, lol, still can't forgive myself) and I like this community quite a bit, but I wish some (small number of) users would take some more pride.

(steps off soapbox, cue patriotic music) kidding, all of the above IMHO!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at an ASCII table: http://web.cs.mun.ca/~michael/c/ascii-table.html how do the two cases relate?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I got this, it's a bit closer. I need to reread the rules as I haven't actually checked all of your if statements versus them. Go through the if statements line-by-line to see if they match. Small changes in these rules can cause large changes in the game.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In fact, now that I think about it further, you need to have specialized sections for row = 0 and row = 19 also. I was testing some points that should be out of bounds on your array and many of them are initialized to 0 which is probably the biggest factor in messing up your counts. So in summary for your "only row" for loops take out the statements with col-1 for col 0 and those with col+1 for col 19, and for those in row = 0 take out the terms with row-1 and those in row 19 take out the terms with row+1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for (int row = 0;row<ROW;row++)
col = 0;
test for this column only (don't test any col-1 points)

for (int row = 0;row<ROW;row++)
col = 19
test for this column only (don't test any col+1 points)

What I'm trying to figure out now is how [row][col-1] for col = 0 is not crashing in your program as it is.

I think we're leapfrogging posts lol.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I did what you said regarding the == and I got more wrong cells...not sure why so I put em all back for now.

I was afraid it might goof you up... well, for next time when you don't have a zillion if /else in there.

I believe this is the problem. When the loop gets to this at column 19:

if(bacteria[row][col]==true&&bacteria[row][col+1]==true)
       {
        neighbors++;
        }

I think it's reading column 0 to find out if there is a neighbor but I don't want it to.

It shouldn't be. If it steps over the end of your array your program should crash. I can't remember if there's anything in your rules about boundary conditions...I haven't tested your posting of your entire code I'll run it if I have a chance.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if(bacteria[row][col]==true&&bacteria[row-1][col]==true)
       {
        neighbors++;
        }

becomes

if(bacteria[row][col]&&bacteria[row-1][col])
       {
        neighbors++;
        }

(and anything X == false becomes !X)
Back to your question, are you saying that your board should wrap around, that is, cols 0 and 19 should affect each other? I think you'd have to take care of a special case rather than modifying all your existing if statements (by putting a %20 to your indicies for example and correcting your -1 index, there may be a clever way to do that which is beyond me, but you see the potential for a mess). I would just run your actual for loop from 1 to 18 and have another for loop over the rows of cols 0 and 19.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You are correct. I think the OP had that in error. What was suggested was return or break not both.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I personally do not have the background. If you are still learning C++ you should get more experience with it before using a complex library and certainly before trying to write one yourself from scratch. Not trying to be harsh but given all of the constraints you have (can you use any libraries at all?-- I know 7-zip has one, I'm not sure if that was in AD's links or if you can use it) it's less than practical.

Apologies that I offered you less than zero software help but I don't have enough specific experience.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ancient Dragon gave you some links to freely available libraries in your other post. If you're up for some theory check out http://en.wikipedia.org/wiki/Lempel-Ziv but it's definitely preferable to use a library rather than re-implementing from scratch. Please elaborate on what help you need with the compression if this is not what you are looking for.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Me again... :) ROW is not in scope in your function (I checked your other post). You'll want to either put it through a debugger (or put in a temporary int variable to count your loops or print out something etc) to make sure it goes through enough loops. It could be that it's skipping the if statements completely.

Also, you don't need to use == with something that's boolean, it already resolves to true or false.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah it does work (I just tried making 3 diff vectors of variable length and putting them into a vector<vector<int> > . It goes without saying but you'd have to make sure if you were using the [][] notation that you didn't step out into undefined territory as my guess would be the second dimension of the vector is defined as the size of the largest vector within it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are referencing those pline values they must exist at that time. Is there a way you could set up SetLine() with default values and then fill them in once you have the pline ones? I understand what you're asking but don't understand how it relates to the dimension (which by virtue of the vector can be adjusted).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, I don't think cin is getting all your numbers in a row like that. I'm trying to reformulate it with a while loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your counter values do not exist outside of the loop scope
e.g.

void getData( int compMenuList[], int counter1)
{
	counter1 = 0;

	cout << "Enter the menu choice(s): ";
for(counter1 = 0; counter1 < 7; counter1++)
	{
		cin >> compMenuList[counter1];

		if(compMenuList[counter1] = -999)
			break;
	}
}

Firstly, counter1 should be passed in by reference void getData( int compMenuList[], int & counter1) since you use it in your other function. But even if you take it in, you use it in a loop as a local loop variable and it's out of scope by the time you would be returning the function. You then tried to use this in PrintCheck and your loops were not being run since your final loop condition was zero. That way you ended up with whatever junk was in memory at the address of the structs. So the solution is to increment it as a counter (counter1++) within the body of the for loop so the value is preserved. Then change the for loop in the Print function to i<counter2 and j<counter2 (not <= as you had it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not change calculateAverage to return a double (so your average isn't truncated) and call the function in place from your "out" processing.

double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60], int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60], int Q6[60], int Final[60],int i)
{
    return ((Q1[i] + Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8);
   //scratch my earlier response, you want to pass in i to get which student to average
// and the fact that you were reading in stuff in this function was "using up" lines of your file		
}

and

out << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(8) << lname[i] << setw(7)<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i]<<CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final,i);

That way you have the calculation the way you want it and can format the return value in whatever way you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

void updateFrequency(int size, char grade[],int A,int B,int C,int D,int F) should have ABCDF passed in by reference as in void updateFrequency(int size, char grade[],int & A,int & B,int & C,int & D,int & F) so that when you are modifying the counts in the function they are changed in main().
Call it as: updateFrequency(size,grade,A,B,C,D,F)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I may be off base about this but since you are not allocating anything dynamically, could you not have

if (w==1)
{ 
         cout<<"You Win!";
         return 0;
 }
else if (w==2)
{                  
         cout<<"You lose!";
         return 0;
}
else if (t==9&&w==0)
{
         cout<<"Tie Game";
         return 0;
}

each time you have this particular control structure? (or break; instead of return 0; as amrith92 said). That way any time there's a decision you're out of the game... maybe I'm missing something. I'm also open to the fact that this is not in the spirit of "best practices."

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you please help us solve this post??
can only ask for what may be an easy solution from you.

You are doing yourself a great disservice with this attitude. You will not learn anything if you just assimilate a solution.

I can get down to one error but it changes as soon as I solve that particular problem.

This often happens unfortunately. Keep attacking the errors starting from the first each time this happens, some of the "downstream" errors clear.

I do not have the answer

Neither do I, but if you post your own code (hint: not reposting stefanies hard work) and the specific errors you are facing (the more specific the better) you can receive help from myself or any other member here.

nor the understanding

I'm sure you have the understanding and if not read your text or do a net search on what you need. There are zillions of code examples out there. I've taken online classes before and I understand some of your frustration but you have your instructor's email and probably a way to contact your classmates (just don't exchange email addys in the posts themselves, that's not allowed).

So, in sum, keep at it and start your own post with what you've got and the specific problems you are having.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Get rid of infile>>row>>col; on line 39, it's reading in 0,0 and throwing it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

OK, I gotcha now. Well you still need to assign something to the bacteria[row][col] for it to show up in your array.

while(infile>>row>>column)
           bacteria[row][col] = 1;

will work. But as part of your design considerations you need to decide what you want those cells to be -- is integer best, or boolean? In other words what will "store' the state of the system the best between iterations.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is a 2D array the best choice here? You have more than one value corresponding to each "row" number?

infile>>row>>col;
    
     while(infile)
     {
     bacteria[row][col];
     infile>>row>>col;
     }
     infile.close();

should probably be something like

int i=0;
while(infile>>row>>column)
{
           bacteriaX[i] = row;
           bacteriaY[i] = column;
           i++;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@jonsca : You can write function definitions without declaring its return-type before-hand, as most compilers treat such functions as integer-returning functions, so here, main() will be taken up to return an integer. So basically, main() will translate to int main() , automatically. This is true for all functions as well.

I understand what you are saying but it is a vestigial feature and at best not a good habit to get into.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This doesn't preclude that. In your outer one you exit from while via the return statement. This one, the break will only exit out one layer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Move that entire line 6 out of main and put it before and outside of main.

Also, main() should always be int main(), returning 0 at the very end

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm sure there are more elegant solutions to this problem, but here's an example I thought of

bool exitloop = false;
switch(ch1)
{
   case 1 :{
       while(1) {
           cout<<" Directory Selection"<<endl;
            cout<<" 1. Computing Science "<<endl;
            cout<<" Enter your choice : ";
            cin>>ch2;
           switch(ch2){
               case 1 : break; //out of inner switch
               case 4 :exitloop = true;  break; //out of inner switch
           }
        if(exitloop)
	   break;  //out of while
       }

   break;  //out of outer switch
	   }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your main should never return void, always an int. You should have return 0; at the end. Using another return statement in the midst of your

if (w==1)                           
   cout<<"You win!";                                   
else if (w==2)
   cout<<"You lose!";
else if (t==9&&w==0)
    cout<<"Tie Game";

might be a good idea. I haven't familiarized myself with your w codes, but if you had a statement

if(win or lose or tie)
      return 0;

and the program would exit immediately at that point.

I think there may be some improvements possible elsewhere but for now this will get your program out of being stuck.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
mi = KM_MI * km;           
gal = L_G * l;

should probably be

mi = (1/KM_MI) *km;
gal = (1/L_G) *l;

because the units should cancel out in your multiplication
mi = (mi/km)*km = mi
gal = (gal/L)*L = gal

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are some missing semicolons and a mismatched brace I think. Your function _definitions_ (at the bottom) do not need a semicolon after them. You don't need to (and shouldn't) redeclare saleAmount and taxAmount in calctotal(). You will override anything in the parameters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

void displayLogFile(void displayLogFile(double totalQuantity, double salesTotal, double tax, ofstream& logFile); something is awry there, I think you just pasted twice. This also needs to be called as displayLogFile() and not cout'ed

And when you call it, use logfile instead of my_ofs, that doesn't exist

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

To get the quantities (I assume you only want total number of items rather than the total number of each?) For that you can put a counter at the end of your ordering while loop so it increments. When you are calling your function you can leave off the ofstream & designator (but you do need it in the declaration up top, so leave that one alone).

In the menu don't put cout<< displaymenu(), just put displaymenu();
otherwise cout would need the displaymenu to return a string in this case.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try the viruses etc forum (also on DW)
http://www.daniweb.com/forums/forum64.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since they are strings these all need to have quotes if(menuItem == "ha" || menuItem == "HA") //Hamburger

To make a log: create an ofstream object e.g., ofstream outfile("log.txt"); check if it's open if(outfile.is_open()) Then use outfile like it's a cout
e.g., outfile<<"Text to print to the file "<<yourvariablehere<<endl;
If you're using it in your functions, pass your ofstream object in (e.g., myfunc(param1,param2, ofstream & my_ofs)

To get the time you can use #include <ctime>. See here for an example to get time and date (ignore the printf, use cout or your ofstream instead).