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

>>//i want to call "displayReport" function i don't know how to do it

First you have to create an object of the class you want to use, then you can call its method(s). I don't see that function doing anything except displaying a welcome message.

GBook book;
book.displayReport();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>and i have a problem in writing the main
If you really wrote the code you posted writing main() should be a breaze. So what is it about main() you can't (or won't) do ?

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

please post the exact code that you wrote. There is no way that the code you posted can produce that output. Just copy it from your program and paste it to here.

>> y=x*z;
And what exactly is that supposed to do? what is z? You can't just toss a bunch of random variables at a program and expect it to work. Programs are executed from top to bottom, so you must code it in the order you want it to be executed. The loop goes first and then the line that does the calculations. I already posted an example of how to do the calculation. If you want to use y as the loop counter, great. Then in the code I posted just replace x with y.

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

>>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

>>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

>>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

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

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

Then I suppose the changes I've posted so far will be ok. You have yet to prototype printCheck(). The code you have at lines 25-35 will have to be moved into that function. That simplifys the main() like this:

int _tmain(int argc, _TCHAR* argv[])
{    
    string date;
    string firstName;
    string lastName;
    double amount;
    enterData(date, firstName, lastName, amount);
    printData(date, firstName, lastName, amount);
    return 0;
}

Now, I'm not going to write the rest of the program for you. You can do that and post code with question(s).

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

Ok, then the code at lines 15-22 should be inside that function and main() should only call it once. Did your instructions say exactly how that function should be prototyped ? Because I think you should pass those parameters by reference so that it can change the values of the variables declared in main(), something like below.

void enterData(string& date, string& firstName, string& lastName, double& amount);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You SHOULD program to ask for those things. How else is the program supposed to know it. And the date should also be a string and not an integer so that you can enter something like "30 Sep 2007"

The parameters on line 17, 19 and 21 do not match the parameters to the function on line 5, so your compiler will complain about that. Since you already coded cin to get the information I see no useful purpose for enterData().

Line 29: you need to change it so that it prints the names that you entered previously. Something like this will do it:

cout << "Pay to the order of: ";
cout << firstName << " " <<  lastName;
cout << "      $" << amount << endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>since it is an online class it is hard to get help
Naw -- there's lots of help here at DaniWeb :)

Appears you have declared variables firstName and lastName incorrectly -- should be declared as std::string instead of char. The way you have it those variables can only hold one character, which I doubt you intended to do. You'll need to change lines 4 and 12, something like this:

#include <string>

<snip>

void enterData(int date, string firstName, string lastName, double amount);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what error(s) do you get?

Move declaration of numz outside that while loop, probably just under the declaration of the other integers.

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

It only counts the number of vowls in the last line read. Move the closing brace at line 27 down to line 39 so that the program will count the number of vowles in every line. Also in line 34 is it not necessary to use isalpha because checking for each vowel letter will do that as well.

>>Our professor wanted us to use a switch/case statement
Then replace that if statement with a switch statement

switch (ch)
{
    case 'a': case 'e': case 'i': case 'o': case 'u':
          // do something
          break;
    default:
         // not a vowel
         break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> It's not generating more than 60 numbers
That's because 207-146-1 = 60 (see line 34)

What's the purpose of the loop at lines 43-48 ? All it does is print several line feeds and you can do that without a loop.

>>It's not being printed in 5 columns.
probably because of the endl at the end of line 38. Looks like you need to move lines 45 and 46 up to line 39, then delete lines 43-48.

>> Is my bubble sort algorithm ok
No. What is this supposed to be sorting? both count and numbers are just simple integers. Only arrays can be sorted. If you want the numbers to be displayed in sorted order then you will have to make numbers and array of at least 60 integers.

Line 50, you are using the wrong comparison operator -- replace > with <.

for (i=0;i < count-1;i++)

Same problem at line 51.

You should also be more liberal with braces. Lines 42-49 should be coded like this:

for (i=0;i<count-1;i++)
{
    for (j=i+1;j<count; j++)
    {
           if (count>numbers)
                swap (count,numbers);
    }
}

Note that you do NOT want the braces at lines 49 and 54 of the code you posted.

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

post new code.

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

look at line 43 -- the condition is wrong because i is initialized to 0, so it will never be greater than 146. And why do you want that loop to print the same value for numbers so many times? numbers never changes value within that loop.

[edit]line 34 is screwy too -- since i is initialized to 147 there is no need to test that it is greater than 146. Just simplify to this:

for (i=147; i < 207; i++)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 38 uses k as the loop counter, but lines 40 and 42 use a different variable. Either correct lines 40 and 42, or change line 38 to re-use i integer (preferred). Programs should attempt to reuse variables, especially one-letter loop counters, whenever possible so that the program has fewer variables and makes it easier to understand.

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

don't check for integer length but check to make sure the program doesn't read in more strings than the array can hold, something like this

int count = 0;
while(count < 120 && getline(inFile,name))
{
    names[count] = name;
    ++count;
}

The above loop when either of the two conditions exist: either the value of count becomes 120 or when end-of-file is reached. After that loop terminates then you can code a bubble sort or some other sorting algorithm to sort the strings.

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

Suggestion: don't attempt to sort the array on every iteration of the input loop. Read all the strings and sort only one time after the loop terminates.

>>int count=120;
initialize that variable to 0 instead of the max array size. Then insert the new string into the array at count element and increment it in anticipation for another string.

int count = 0;
while(getline(inFile,name))
{
    names[count] = name;
    ++count;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think you can ignore the last letter thing -- just sort according to normal descending sort rules and the last letter will fall in line correctly.

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

Does the id array sort properly ? If not then you need to rethink the algorithm. Get that array sorted correctly first then you can add the code to swap the other array at the same time the id array elements are swapped. If you need a selection sort algorithm just use google and you will find lots of them.

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

First, you need to make variable pass one byte larger so that is can contain the normall c string null terminator. Then lines 7-13 can be simplified like this

char pass[] = "pasqwe";

Notice you don't have to specify the size of the array when initializing it with a string like I did above. The compiler will figure that out itself.

Now in line 18 you probably should use a different variable so that it can be compared to the original. Line 22 can use strcmp() function to compare the two strings instead of comparing them one character at a time. Here, variable new_password is another variable I mentioned previously that is entered on line 18.

while( strcmp(new_password, pass) != 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Maybe he just is a bad lawyer? It's been my experience that people get jobs outside of their degrees either because they fell in love with an industry too late (i.e. after school) or because they aren't good enough to make it in what they have a degree in.

Could also be some people just get bored with their profession and want a change (burnout).

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

>>so considering the fact, that each line in the inFile contains all leters of the alphabeth, at some point or the other....i'd have to use a lot of if-else statements? For example... if (x>y)...all the way down?

Naw -- it is not that hard. What jamthwee posted was just an example to show you how to compare two strings. Since you have them in an array you can use a loop to run through them exactly like you would sort an array of integers. Like this bubble sort algorithm -- there are other more efficient sort algorithms, but this is ok for small arrays.

string names[25];
for(int i = 0; i < 24; i++)
{
   for(int j = i+1; j < 25; j++)
   {
       if( names[i] > names[j])
       {
            string temp = names[i];
            names[i] = names[j];
            names[j] = temp;
        }
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

a vector is a c++ array class, so just use a loop to access each Pizza object

int n = theOrders.size(); // get number of elements in the array
for(int i = 0; i < n; i++)
{
   outOrder(theOrders[i]);
}

You will want to add a parameter to outOrder function, similar to the parameter to addPizza().

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

If Order can contain one or many pizzas then it should have a vector of pizza objects, and pass the Pizza object by referenct so prevent unnecessary duplication of the object.

class Order
{
public:
    void addPizza ( Pizza& order) ;
    void outOrder ( ) ;
private:
    vector<Pizza> theOrders;
} ;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

strstr() expects the first parameter to be a char* pointer, not a std::string object. use the c_str() method to get the pointer

strPtr = strstr(phone_book[index].c_str(), lookup);

But you don't need to use strstr() at all because std::string has a lookup function called find(). It returns an int to the beginning of the string or string::npos if not found

std::size_t pos = phone_book[index].find(lookup);
if( pos != string::npos)
{
   // found it
}

I wrote the above from memory so I hope its corect. If not the someone else will correct it.

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

Are you using MFC or pure win32 api? My best suggestion for you is to download the several example programs you can find with google and try them out. Nothing helps one understand a problem like practicle demonstration.

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

Your code is missing closing brace and semicolon at the end of the class declaration and before main() on line 58. After correcting that you can probabably figure out how to correct the other one million errors.

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

line 5 should be delete[] Entry

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

>>int HotDogStand:: totalSales = 0 ;

this line goes into a *.cpp file, not the *.h file because it actually declares an object.

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

>>There are many places where being off by just 1 character can radically alter the behaviour of a program
OMG its sooo true, I've had that happen all too often.

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

IMO, you need to create a new project and build up slowly this time, copy/pasting small sections of this project to it, along with lots of compile and test as you go.

Yup, I suggested that too, but I suppose some people don't take suggestions like that.

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

forget about the semicolon for now, just concentrate on finding the mismatches braces. Books sometimes contain errors due to poor or inadequate proofreading -- or more likely you copied it wrong.

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

Ok I loaded your code in a new project with VC++ 2005 Express and found that your Form1.h is missing some braces somewhere. You need to start at the top of the file and count the number of open/close brace pairs and insert the missing one(s). Put your cursor on the closing brace at the bottom of the file then press Ctrl + [ keys and the cursor will jump to the matching open brace.

After adding two closing braces at the bottom of the file (probably in the wrong place I might add) the compiler now spits out a lot of other errors in Form1.h. My suggestion is to begain all over again, create a new CLR Windows project and gradually add the code you posted here a little bit at a time, compile to get clean compile, then add some more.

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

Well and you, Ancient Dragon, should understand the same as well. You in addition to everything blocked your private messages for me

Huh? If you mean I have you on my ignore list ... I don't. I never block PMs -- ever. The initial PM you received was automatically generated by the system when I gave you the infraction. It works that way with everyone. And I think you get other autogenerated PMs when someone edits your posts.

except for asking to leave me alone

I only sent you courtesy PM in reply to the PMs you sent me.

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

I think you well understand that you can allow yourself anything now, you cut my tongue, and i may not even be able to reply. All the words are meaningless after that.

That really isn't true -- you cut your own toung by posting abusive and malitious language about another member (did you bother to read the Rules ?). Otherwise you are pretty much free to post anything you want as long as it doesn't violate other DaniWeb rules.

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

without attempting to compile the code you posted there is probably at least one semicolon missing at the last brace in the header file.

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

i am using Vista Ultimate, does this matter?

No -- that error has nothing at all to do with the operating system. Without seeing your code I guess that you left out a semicolon somewhere.

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

you header file need code gards to prevent that, like this

#ifndef MYHEADER
#define MYHEADER
// code goes here

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

getchar is the standard C library function. Borland compiler has many functions that have no standard C library equivalent, such as everything in graphics.h.

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

Oops! my error -- you are correct that you can not use cin and cout in C. I had c++ in mind. Sorry for that gaff. :icon_redface:

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

also, learn to use c++ cin and cout to simplify your code. you can replace printf() with cout and scanf() with cin.

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

simple solution -- move lines 28 and 42 up to line 7 so that its scope is to the entire function. Also you can't declare a matrix using non-static number of elements. If you don't know the size of the matrix at compile time then you have to allocate the dimensions with malloc()

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

Yes, wrapper is the way to go then just use precompiler directives to conditionally compile depending on the os.

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

ms-windows call GetFirstFile() and GetNextFile(), or in *nix call opendir() and readdir(). If you used c++ you can use boost library that is portable between these two operating systems (I don't know a thing about MAC).