Hi guys i need a little back up on my code.. thankz4ur time

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 596 Views - Last Post: 26 October 2013 - 08:43 AM Rate Topic: -----

#1 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 02:38 PM

Sooo... yea im working a little project and im a little stuck im making an array that saves data the data is a pigs farm and I need to keep track of how many pigs are brought to me, the name of the other farm that send the pigs, the name of the employee that brings the pig and how much the pig weights... this is what I have sofar
// I have deleted the code because some others students from my class room also use the web page and there stilling my ideas and passing them as there own..to see the code reply and il post it agen

}[/code]
all I need for now is a way for the program to save the pigs data the user input into the program..
(cerdos[2][1] = cerdos [0][0] ++ );

		cout<<cerdos[2][1]<<endl;

this is what I try to keep the pigs number the user inputs into the program to add up.. but it dosent work can some 1 give me a push in the correct direction.! thankz

This post has been edited by Edisonpr93: 26 October 2013 - 07:13 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Hi guys i need a little back up on my code.. thankz4ur time

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 02:42 PM

Quote

> all I need for now is a way for the program to save the pigs data


I would suggest a database.
Was This Post Helpful? 0
  • +
  • -

#3 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 02:53 PM

View PosttlhIn`toq, on 25 October 2013 - 02:42 PM, said:

I would suggest a database.

I don't follow..
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,562
  • Joined: 25-December 09

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 03:05 PM

What have you tried? The code you posted doesn't really show much effort, so you'll need to do at least a couple of things.

1. Ask specific questions.

2. Show some code that actually shows some effort. Perhaps you should start by getting your program to get the input for one "record".

You seem to know about arrays, but it doesn't look like you really understand them. Maybe you need to restudy your textbook? Here is a basic tutorial you may find of use: Arrays.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 06:18 PM

Ok guys here is the complet code... just finish

all im missing that I cant find a way I need a variable to add how many pigs I have sold each time I use the code

// I have deleted the code because some others students from my class room also use the web page and there stilling my ideas and passing them as there own..to see the code reply and il post it agen
[/code]

This post has been edited by Edisonpr93: 26 October 2013 - 07:12 AM

Was This Post Helpful? 0
  • +
  • -

#6 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 06:35 PM

Add an int pigsSold=0 variable before any pigs are sold, and then increment it as your code sells each pig?


If selling just parts of a pig, can add up to equal a pig being sold, then use a double for the pigsSold=0.0 variable, instead of an integer.
Was This Post Helpful? 0
  • +
  • -

#7 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 06:37 PM

View PostAdak, on 25 October 2013 - 06:35 PM, said:

Add an int pigsSold=0 variable before any pigs are sold, and then increment it as your code sells each pig?


If selling just parts of a pig, can add up to equal a pig being sold, then use a double for the pigsSold=0.0 variable, instead of an integer.

mm yes I get what your saying but how can I make it add the pigs sold each time the program re loop it self.. get what im saying?
Was This Post Helpful? 0
  • +
  • -

#8 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 06:51 PM

If you want it to keep the pigs already sold total, then declare the pigsSold variable before the menu begins, and be sure to set it to zero.

If you want it to reset to zero every time the menu starts over, then add pigsSold=0 to the very top of the while() loop for the menu.

If you want it to remember ALL the pigs, even when the program has been shut down, then you'll need to have the program write that information out on a file, and read it in, every time the program starts up.

This should be VERY basic stuff by now. Find a good tutorial for C, and work through it. There are many good one's out there.
Was This Post Helpful? 0
  • +
  • -

#9 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 07:05 PM

View PostAdak, on 25 October 2013 - 06:51 PM, said:

This should be VERY basic stuff by now.

Im a noobie programmer :D but thankz for your time
Was This Post Helpful? 0
  • +
  • -

#10 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1678
  • View blog
  • Posts: 3,180
  • Joined: 30-May 10

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 25 October 2013 - 10:44 PM

009 type [0][0] = 3.50;//***************
010 type [0][1] = 3.00;//precio de los flacos
011 type [0][2] = 2.15;//***************
012 type [1][0] = 3.75;//*****************
013 type [1][1] = 2.50;//precio de llenitos
014 type [1][2] = 2.05;//*****************
015 type [2][0] = 4.50;//******************
016 type [2][1] = 2.00;//precio de gordos
017 type [2][2] = 1.75;//******************


I suggest you go and read Jim's tutorial link for arrays (perhaps for the first time).
All the red lines are out of bound accesses.
You have 4 slots, not 9.
Was This Post Helpful? 1
  • +
  • -

#11 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 26 October 2013 - 04:27 AM

View PostSalem_c, on 25 October 2013 - 10:44 PM, said:

009 type [0][0] = 3.50;//***************
010 type [0][1] = 3.00;//precio de los flacos
011 type [0][2] = 2.15;//***************
012 type [1][0] = 3.75;//*****************
013 type [1][1] = 2.50;//precio de llenitos
014 type [1][2] = 2.05;//*****************
015 type [2][0] = 4.50;//******************
016 type [2][1] = 2.00;//precio de gordos
017 type [2][2] = 1.75;//******************


I suggest you go and read Jim's tutorial link for arrays (perhaps for the first time).
All the red lines are out of bound accesses.
You have 4 slots, not 9.

oh.. thast way its not giving me results..
Was This Post Helpful? 0
  • +
  • -

#12 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 26 October 2013 - 04:51 AM

If you have an array type[2][2], valid indices are ONLY 0 and 1 - never 2!

type[0][0] OK, type[0][1] OK, type[1][0] OK, type[1][1] OK.

Anything else is OUT OF BOUNDS and will ruin your program! All arrays in C and C++ are zero based, not one based.
Was This Post Helpful? 0
  • +
  • -

#13 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 26 October 2013 - 04:57 AM

View PostAdak, on 26 October 2013 - 04:51 AM, said:

All arrays in C and C++ are zero based, not one based.

Yea I know it slip my mind when I was fixing it... but thankz

View PostAdak, on 25 October 2013 - 06:51 PM, said:

If you want it to keep the pigs already sold total, then declare the pigsSold variable before the menu begins

I like this answer.. what did you mean before the menu begins?? before the (while) or before the void main() like a function?
Was This Post Helpful? 0
  • +
  • -

#14 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 26 October 2013 - 05:38 AM

Before the menu begins - somewhere inside the function, but before you begin selling pigs. Just be sure to initialize your pigsSold variable to 0.

Global variables are automatically set to zero, but all the variables created inside a function, are created with just garbage values - not zero. So it's up to you to do it.
Was This Post Helpful? 0
  • +
  • -

#15 Edisonpr93  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-September 13

Re: Hi guys i need a little back up on my code.. thankz4ur time

Posted 26 October 2013 - 05:39 AM

check out the keeping track variable I made but is now working did I put it on a the wrong place of is not a good way of adding up numbers?
// I have deleted the code because some others students from my class room also use the web page and there stilling my ideas and passing them as there own..to see the code reply and il post it agen

This post has been edited by Edisonpr93: 26 October 2013 - 07:11 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2