jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Excellent with the code tags. The rest of it, I'm not sure what you did. You seem to have tossed in some pseudocode ("end if"??) up at the top. You corrected what is now on line 55, which was good, but you haven't corrected anything in your Account::output method. What kinds of errors are you getting now (besides the treasure trove from putting that p-code there)?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Code tags: it's simple. Type:

[code]

//paste your code in here Type:

[/code]
(or highlight your entire code and click on the [code] button on the editor toolbar.

Now, there's a simple error hampering your progress here:

void open_input(ifstream& input, char name[])[COLOR="Red"][B];[/B][/COLOR]

(that would have been on line 37 had you put code tags)
Again you're still missing a semicolon here as you were told in the other thread. Always start with the first error, correct it and some of the others will fall away as a result.

There are still problems with your output method. What are InterestDue,TotalAmountDue and Payment? How would we normally call (invoke) such things?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

but wasn't detailed

That's because I can't have all the fun... :)

Get some of the initial set-up done with the arrays declared and try the getInput function (as those parts are probably not new to you) and post back with what you have. You must put forth the effort and we will be glad to help.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Say you had an array of titles an array of authors and an array of prices. Imagine it in a table format:

Index        Author       Title         Price
0              Smith        Why?          10.00
1              Jones        My Book      15.00
2              Jonsca       What?         25.00

So the author array would hold Smith, Jones, and Jonsca but the index of the author would be the same as the index of his book in the book array. So one your functions will allow you to ask who is the author of the book "My Book"

if the user chooses to search by title, call a function with the following prototype:
void searchTitle(char input[], char t[][SIZE_COL],char
a[][SIZE_COL], double p[], int size);

So you'd pass this function: the title you were looking for, the array of titles, the array of authors, the array of prices, and the size for all these arrays (since we're keeping the indexes lined up they should all have the same size). You'd check each entry in the titles array for the one you entered and then get the appropriate index which can be used in the author array to find that it is Jones's book.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Read ('A' <= && c <='F') over. Something's amiss.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Give this a read: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046139290&id=1043284392 and using your square data.txt squares.txt example from above either write a separate small program (that you can probably cut and paste into your larger one anyway) or make it so your program prints out the filenames "data.txt" and "squares.txt" or whatever you pass into it on the command line. Once that's done (with a few adjustments) you should be all set with your program.

An excellent mini-tutorial by Narue on which the "ink" is barely dry:http://www.daniweb.com/forums/post1175948.html#post1175948 (it's in the C forum but I don't know of any nuances in using them in C versus C++)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you know what argc and argv are? Have you written anything where you've had them as parameters for main?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i think it has to do with pointers and memory location
but i don't know exactly what to change to make it work

It actually has to do with the fact that scanf uses a space as an input delimiter (so once it hits a space it stops) and the rest of what you typed stays in the input stream and gets collected by the next scanf.
fgets works very nicely to get a full line of input.
Use the syntax fgets(Videos[i].title,sizeof(Videos[i].title),stdin); . The function will put a '\0' at the end for you so that will only leave you with 19 characters to play with. fgets will take in the '\n' at the end of a line so you can step through the string and replace '\n' with a '\0'

other question: how do I return to main from the functions?
I mean , i want to finish my work (adding, modifying,deleting,listing)
then return the value to main and go there and when i want to list
the movies I want to see the latest modifications.

Wrap from lines 28 to 48 in a do/while loop while n !=0. This way when your functions return to main() it'll be primed for another time through the menu. When the flow of the program reaches the end of a void function the flow returns to the calling function (same as it would if your function returned a value and the flow hit a return …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay. Good effort in posting something (and not copying the other post). For next time if you use [ ] in the code tags like

[code] [/code] (there's still time to edit your post with the edit button in the lower left corner).

Now the question is does it work as is at this point? (does it read in the numbers correctly and output the right answers)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to escape the backslashes with another backslash (just like using a backslash to escape double quotes and the like): system("c:\\new\\ram.bat");

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Not a problem. Keep mitrmkar's comment in mind too, he makes a good point.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the future please try to refrain from giving away a code sample that an OP can turn around and hand in for a grade (as I'm doubtful that not having exceptions and type safety will hinder that). Guide the poster through the process and help him/her reach the conclusions that they need to.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Without something to go on I don't know where your difficulties are. Can you write a program to read a data file? Can you write a program that writes a data file? Can you write a program that squares numbers? Start on one or more of those pieces and post back some actual code.

Also, it is disrespectful to tell us that something is urgent. Your rush does not become our rush.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried thusfar?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a closer look at line 21. The statement meant to be associated with the "if" was being executed regardless. Can you see why?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I am trying to use a "while" loop because that is the chapter we're on.

The input is done by keyboard and the professor has hinted we should use some kind of "while input is good" event test for exiting the loop. We've done that sort of thing for reading from a file, but I don't know exactly how to do it for a cin string.

But with the std::string you have the information about the length already. You should probably use it, like you tried to in your example


while (count < length)

get next letter, if capital then charactrCtr = charactrCtr +1
++count

I don't know the proper command for the "get next letter" bit, though.

Sorry to be a doofus, but I don't understand exactly how to do this, even with your suggestion of "Use a for loop and march through the string by index (in string mystr = "abcd"; mystr[0] is 'a',mystr[1] is 'b')"

Is it possible to initialize count to 1, then use the count to point to the "next" letter?

Yep. That's what I was trying to say. In your snippet above if count starts at zero then userInput[count] would give you the letter at the "count" position (zero based).
So something like

string userInput = "input";
int count = 0;
while(count < userInput.length())
     cout<<userInput[count]<<" ";

would get you "i n p u t". That's all I meant when I said marching through the string. I happened to suggest …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I agree with Adak's suggestion. Part of the problem is that you are trying to write a string of unknown length to an (uninitialized) char array. Rather than having to "malloc" your way through you could make your array 3 dimensions (of char not char *) and would allow you a fixed amount of room in which to write characters (again the typedef makes things a bit confusing here for you as the programmer).
Either way, you should consider using fgets to read your strings in. An additional perk with doing that is being able to input titles, etc. with spaces in them.
One last thing is, don't call main() like you did on line 199. Let the other functions finish up and return rather than calling Exit().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sure, I mean I could probably recreate it (since it's just your includes and a typedef or two) but it'll be faster.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would take a minute or two and get the formatting all straightened out (get stuff tabbed in and line up all the opening and closing braces with each other) and the answer should be evident.

(Post 2000)-- ignore this

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no i'm not ok.

what should i do?

Put a link to some stupid site in your signature and get paid for it! That's made the OP mighty chipper.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post up the entire code so I can try it out?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Never mind everybody, I got it working. Thanks anyways.

How did you fix it? (I'm just curious)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think the problem is that strstr doesn't work the way you think it does. I'm not ultra proficient in the <cstring> functions but I believe it will locate the second argument as a substring of the first argument (and return the position if it was found). You may find that the std::string methods are more useful in this type of application.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What is it doing when it blows up? Can you put some couts in it to "debug" it in release mode?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In all 3 cases you are reading your strstr result into pch rather than pch1 or pch2 in the second and third cases. I think you should declare pch,pch1,pch2 outside of the loop and set them to null at the top of the do/while loop. Since you do not initialize any of the pchs there is a good chance that any one of them is non-null when you check them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does it rely on a file that it looks for in the same directory as the application? If so you need to copy that file from the debug to the release folder.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if (pch1 != NULL)
     {
        cout << "My name, you say\n"
             << "It is Jubajee\n"
             << "Cool eh?\n";
             redo = 1;
     }

Are you talking about the above printing out

My name, you say
It is Jubajee
Cool eh?

all at once?
I'm unclear on what you mean by that.

Where does it go after the output of the phrase if it doesn't loop through one more time?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So the healthy eating ethic and the non-spamming ethic don't overlap?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How are you using "string" in C? Are you compiling it as C++?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's doing exactly what you asked it to. You're having the program look for when the text has changed in the textbox (so if you type in any characters that event is firing with each one) and outputting the results to the file. You are getting the text of entire textbox written out each time and the entries are being appended after one another.
You need to either wait for the user to press enter or put a "send" button on the window.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Write a program that will first fill two out of three parallel arrays (local to the main function)
with user-supplied data and then give users the choice to query the parallel arrays. The first
array is as follow:
char title[SIZE_ROW][SIZE_COL]={"Intro to Calculus", "C++
Programming", "Java Programming", "Intro to Psychology", "Intro
to Business"};
Call a function with the following prototype:
void getInput(char t[][SIZE_COL],char a[][SIZE_COL], double p[],
int size);
to fill in the other two local arrays, authors and price.

Can you implement the program up until this point? Try to get that far based on what you already know from class, post your effort thusly and someone should be able to help you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't have to go through all this as Write() has an overload that takes a string directly. If you had to go the route you planned you can use the ToCharArray() method of the string to get the array that you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There were a lot more errors than 2. In your output function you are missing some pairs of parentheses.

As Excizted mentioned please learn to use code tags. Type in

[code]

//code goes here

[/code]
It makes it very difficult to see what's going on with your code when the formatting is removed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm basing my opinion on this snippet that I wrote

char cabin[3][13][4];
ifstream ifs("littleswandb.txt");

for (int l = 0;l<3;l++)
	for(int r = 0;r<13;r++)
		for(int c = 0;c<4;c++)
			ifs>>cabin[l][r][c];

for (int l = 0;l<3;l++)
{
	for(int r = 0;r<13;r++)
	{
		for(int c = 0;c<4;c++)
		{
			cout<<cabin[l][r][c]<<" ";
		}
	cout<<endl;
	}
cout<<endl;
}

It takes in the data properly and outputs exactly what was in the file. No need for a "rubbish" variable.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
//or if you wanted to call a function or variable without declaring an object
//just like namespaces
foo::color(RED);

cout<<foo::x;

This only works if the function or member variable is static so ignore that bit for a moment (see below for a link to more info). Otherwise you need an instance of the class.

objectOne.x=3 //example with using the object name instead of the 
//classes
}

That approach using the dot to access members is more along the lines of what you are looking for.
So in your main you could have

Complex c1(1,1);
Complex c2(5,13);
std::cout<<c1.getRealPart()<<std::endl;
std::cout<<c2.getImaginaryPart()<<std::endl;
//and then declare a third complex number c3, and use the add method of c1 to sum c1 and c2 and assign it to c3.

If you are interested in information on static member functions and variables give the bottom half of this a read.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm trying my best to learn linked lists but am having a difficult time understanding them exactly any way debugger returns SIGSEGV

#include <iostream>
using namespace std;


    typedef struct node *p;
    typedef struct data * d;
    struct node{
        p next;
        d dat;
        };
        struct data{
            int id;
    };

int main(){
    int x;
    p root = new node();
    d base = new node();
        base->id=0; //first error was here
    if(x!=20){
        root->next=new node; // i believe this is my problem but im not sure how to fix it. this is also my first time using the -> which i understand to be "points to"? 
        base->id=base->id++;
        cout<<base->id;
        x++;
    }
}

You had initialized the pointer for root->next but you hadn't initialized root nor base yet.

-> is just shorthand for dereferencing a pointer to a struct or object and subsequently calling a member function or accessing a member variable. So if you had a class MyClass which had a (public) member named mydata and a method named getData and you had MyClass * instance in your program you could call (*instance).getData() or in shorthand instance->getData() .Same goes for (*instance).mydata versus instance->mydata .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why have the while loop at all? You have the length of your input on line 17 and all the loop on line 20 is going to do is ask for more input. Use a for loop and march through the string by index (in string mystr = "abcd"; mystr[0] is 'a',mystr[1] is 'b')

Also to assure portability of your code use 'A' instead of 65 and 'Z' instead of 90, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at lines 21,23,25. Now look at line 27. You are still not being consistent with which variable is which. It should be [l][r][c] on line 27. If you read along your first output that looks jumbled the proper order of the letters is there but the pattern is all scattered. Unfortunately all you've done is put a band-aid over a huge bug.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

im not sure wat ur asking me here

Was asking if he/she would change the number of rows or what each row contained or really anything that would require the loops to change based on the data. If you've used the for loops below I'll take that as a no.

and i thought about something like this for the for loop instead of the if statements
im testing out now

cout << ch;
             indata >> ch;
             for(int l =0;l>3;l++)
             {
                 //cabin[l][c][r] = ch;
                 for(int r=0;r>13;r++)
                 {
                     //cabin[l][r][c] = ch;
                     for(int c=0;c>4;c++)
                     {
                         cabin[l][c][r] = ch;   
                         cout << cabin[l][c][r];
                     }
                     cout << endl;
                 }
                 cout << endl;
             }

There's a couple of gotchas in the above code. You put the greater than signs by mistake. Also you are inconsistent as to the order of l r c (some of the lines were commented out) Make sure you keep those in the proper oder What you have there is along the lines of my thoughts -- you should just eliminate the indata>>ch and use indata >>cabin[l][c][r]; (or [l][r][c] whatever you decide) in the middle there(line 11, unlabeled ). Changing the variables back to that [L][R][C] order is more in line with how your datafile is laid out -- just be sure to keep consistent!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Will your instructor vary up the input file any? Since you are hard-coding the array dimensions anyway you could potentially (though with loss of flexibility) get your input via 3 nested for loops stepping through the array.
This

if(c>3)
{
      c=0;
      r++;
      cout << endl;
}

if(r>12)
{
      r=0;
      l++;
 }
  c++;

may or may not work but it's kinda kludgy either way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes and change it down where you display the entry after entering it in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have selected a Windows GUI application project within the IDE. I haven't used C::B in a while so I don't remember their terminology but you want to select a "console application" instead. Start a new console project and import your code back into it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I haven't been able to find it either. I know on the test run that I just did I added a reservation at 2 4 4 and it showed up in array postion 1 3 3 like I expected but it also showed up in 0 7 3 (another run had 2 5 2 show up as 1 4 1 and 0 8 1. I'm sure you'll kick yourself when you find it...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yeah, I think I hadn't uncommented the spot where you add 1 back to all the values. Shouldn't have made a big deal. This time it adds two reservations to the ship the first time but I still don't get any junk output.

You have booked the Cabin on Level: 1 Row: 7 Colunm: 2
****
****
****
****
****
****
*X**
****
****
****
****
****
****

****
****
*X**
****
****
****
****
****
****
****
****
****
****

****
****
****
****
****
****
****
****
****
****
****
****
****

Would you like to try another cabin? Y/N
y
Which Level Would you like to reserve? 1-3
3
Which Row Would you like to reserve? 1-13
12
Which Columm Would you like to reserve? 1-4
4
You have booked the Cabin on Level: 3 Row: 12 Colunm: 4
****
****
****
****
****
****
*X**
****
****
****
****
****
****

****
****
*X**
****
****
****
****
****
****
****
****
****
****

****
****
****
****
****
****
****
****
****
****
****
***X
****

Would you like to try another cabin? Y/N
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a sample from one run. It doesn't seem to have booked the last entry but the first two worked:

You have booked the Cabin on Level: 1 Row: 3 Colunm: 2
****
****
****
****










****
****
***X
****










****
****
****
****










Would you like to try another cabin? Y/N

You have booked the Cabin on Level: 1 Row: 2 Colunm: 1
****
****
****
****










****
**X*
***X
****










****
****
****
****










Would you like to try another cabin? Y/N
y
Which Level Would you like to reserve? 1-3
3
Which Row Would you like to reserve? 1-13
13
Which Colunm Would you like to reserve? 1-4
4
You have booked the Cabin on Level: 2 Row: 12 Colunm: 3
****
****
****
****










****
**X*
***X
****










****
****
****
****










Would you like to try another cabin? Y/N
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use Int32::TryParse instead of the Convert call. It's safer and it will return false if it fails versus throwing an exception. You'll have to have a tracking reference int % aout = a; to get the value back from TryParse, but declare "a" as a regular old int and you should be able to call ToString() on it directly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i changed my while loop to look like this:

while (indata != NULL)

If it still works fine but my intention was something different. I'll show you what I mean when we get this other bit straightened out.

Also i changed my array to initialize it, using a blank space, an 'X' and a 'B'. and it seems that is what is the first character that comes up when i output the data later in the program.
Also i am still getting alot of spaces and then a few lines and spaces of the symbols still

Can you put up the code that you used to initialize it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use strcpy to copy those values into the character array:

#include <cstring> //to access strcpy
switch(col)
{
   case 1:  strcpy(text,"0x00000000");
   break;
      //etc.
}

You can only assign text to a character array in the manner that you are trying when it is first declared.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Jonsca:
by "infile.eof()" do you mean "indata.eof()"? and if i take it out that will mean that it will not know when to stop reading the file.

Yes I meant indata. I'm talking about a situation where you use your indata>>ch as the loop variable for the while loop so that when you run out of characters it returns null and the loop ends. The .eof method is prone to scanning in the last character multiple times. Read this post by Dave Sinkula it gives all the details. For right now, though I don't think it's the primary problem but I was examining it as a possibility before.

WaltP:
when it reads a character i get it to display the character so that i can see that it is reading it right. am i doing it wrong?

Unless you're doing something fluky both times and everything's coming out right side up by chance I think that part is ok. Don't quote me on that.

what i want to do with the data later on is change one char, in a certatin spot in the file to an 'X' to represent a reserved spot in my database.

jonsca:
i changed line 9 to what u said but now i am getting a bunch of blank spaces and an 'X'. and then more spaces then another 'X', then spaces and random symbols again.

And it seems to be doing that okay on my end it's just there's …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change line 9 to: char cabin[3][4][13]= {' '}; ** I should have thought of this earlier but the array was not initialized so you were printing out junk characters that were there when the array was created.
It may not solve all the problems but this explains what you were seeing.

I think the input is probably ok as it echos properly on the screen.

** This seems to work but I do not know if that's the proper way to do it. It won't allow any other characters in it's place.