You need to reset your variables after each line.
The Big Programming Thread - Page 88
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
![]()
tofucake
Hyrule18969 Posts
You need to reset your variables after each line. | ||
Frosticles
United States50 Posts
| ||
![]()
tofucake
Hyrule18969 Posts
| ||
sekritzzz
1515 Posts
Any advice to newcomers(ex:me) is greatly appreciated, could always learn from more experienced people. | ||
![]()
tofucake
Hyrule18969 Posts
On the other hand, if you want to do programming you're going to want to focus more on a "traditional" language, typically of the C family (or Java if you hate yourself). | ||
Frosticles
United States50 Posts
inFile >> partnum >> intialamnt >> qntysold >> minamnt; while (inFile.good()) { currentbalance = (intialamnt - qntysold); cout << partnum << " " << currentbalance << " " << qntysold << " " << minamnt << endl; inFile >> partnum >> currentbalance >> qntysold >> minamnt; currentbalance = 0; initialamnt = 0; qntysold = 0; } and it is now giving me error messages... 8.2_9.cpp: In function `int main()': 8.2_9.cpp:36: error: `initialamnt' undeclared (first use this function) 8.2_9.cpp:36: error: (Each undeclared identifier is reported only once for each function it appears in.) 8.2_9.cpp:43:2: warning: no newline at end of file I understand the concept of what your saying, but I don't understand how to implement it in my code. | ||
![]()
tofucake
Hyrule18969 Posts
Also I see you're reading and then trying to reset some stuff. Odd way of doing things. | ||
Frosticles
United States50 Posts
| ||
![]()
tofucake
Hyrule18969 Posts
| ||
Frosticles
United States50 Posts
+ Show Spoiler + #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; int main() { string filename = "inventory.txt"; ifstream inFile; string partnum; double intialamnt = 0; double qntysold = 0; double minamnt = 0; double currentbalance = 0; double minlevel; inFile.open(filename.c_str()); //opens the file if (inFile.fail()) { cout << "The file was not successfuly opened" << endl; exit(1); } inFile >> partnum >> intialamnt >> qntysold >> minamnt; while (inFile.good()) { currentbalance = (intialamnt - qntysold); cout << partnum << " " << currentbalance << " " << qntysold << " " << minamnt << endl; inFile >> partnum >> currentbalance >> qntysold >> minamnt; currentbalance = 0; initialamnt = 0; qntysold = 0; } inFile.close(); return 0; } | ||
Deleted User 101379
4849 Posts
On October 21 2011 04:49 Frosticles wrote: I tried coding it like this inFile >> partnum >> intialamnt >> qntysold >> minamnt; while (inFile.good()) { currentbalance = (intialamnt - qntysold); cout << partnum << " " << currentbalance << " " << qntysold << " " << minamnt << endl; inFile >> partnum >> currentbalance >> qntysold >> minamnt; currentbalance = 0; initialamnt = 0; qntysold = 0; } and it is now giving me error messages... 8.2_9.cpp: In function `int main()': 8.2_9.cpp:36: error: `initialamnt' undeclared (first use this function) 8.2_9.cpp:36: error: (Each undeclared identifier is reported only once for each function it appears in.) 8.2_9.cpp:43:2: warning: no newline at end of file I understand the concept of what your saying, but I don't understand how to implement it in my code. check the spelling of your variables. | ||
sekritzzz
1515 Posts
On October 21 2011 04:48 tofucake wrote: Stuff is broken down into languages (or groups, ie HTML/CSS/Javascript). The particular section you read really depends on your interests. If you want to do website type things, HTML/CSS/Javascript are basically required (not so much Javascript). Actual programming in terms of web stuff will likely be PHP, ASP (.Net in general), or Perl. On the other hand, if you want to do programming you're going to want to focus more on a "traditional" language, typically of the C family (or Java if you hate yourself). Are all groups separate or is one group a prerequisite to doing the job of another group? I'm more or less interested in making programs which probably fall into the "C family". Should I learn other languages before going into it or can I nosedive in? Also is it feasible for me to do a daily job and attempt to learn all 3 or should I concentrate my efforts towards one thing? I get the feeling that when it comes to programming, its more efficient to stick to one thing due to its never ending possibilities of progress. | ||
Frosticles
United States50 Posts
QA310 48 47 50 CM145 0 0 200 MS514 0 0 25 EN212 0 0 160 heres the source code again + Show Spoiler + #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; int main() { string filename = "inventory.txt"; ifstream inFile; string partnum; double initialamnt = 0; double qntysold = 0; double minamnt = 0; double currentbalance = 0; double minlevel; inFile.open(filename.c_str()); //opens the file if (inFile.fail()) { cout << "The file was not successfuly opened" << endl; exit(1); } inFile >> partnum >> initialamnt >> qntysold >> minamnt; while (inFile.good()) { currentbalance = (initialamnt - qntysold); cout << partnum << " " << currentbalance << " " << qntysold << " " << minamnt << endl; inFile >> partnum >> currentbalance >> qntysold >> minamnt; currentbalance = 0; initialamnt = 0; qntysold = 0; } inFile.close(); return 0; } | ||
![]()
tofucake
Hyrule18969 Posts
On October 21 2011 05:06 sekritzzz wrote: Are all groups separate or is one group a prerequisite to doing the job of another group? I'm more or less interested in making programs which probably fall into the "C family". Should I learn other languages before going into it or can I nosedive in? Also is it feasible for me to do a daily job and attempt to learn all 3 or should I concentrate my efforts towards one thing? I get the feeling that when it comes to programming, its more efficient to stick to one thing due to its never ending possibilities of progress. Nosedive! HTML is probably irrelevant if you want to do C stuff. For C, you basically need to use a tutorial if you're completely unfamiliar with programming. What I've found with programming is that once you learn programming, most languages end up being more like tools, and after a while end up being pretty easy to pick up. The important part is learning programming though, so decide on a first language to use and try not to stray for a while. | ||
![]()
tofucake
Hyrule18969 Posts
On October 21 2011 05:08 Frosticles wrote: Ok I fixed the spelling errors, but now my output looks like this.... QA310 48 47 50 CM145 0 0 200 MS514 0 0 25 EN212 0 0 160 heres the source code again + Show Spoiler +
First: code tags Second, I gave you a hint already! On October 21 2011 04:51 tofucake wrote: Also I see you're reading and then trying to reset some stuff. Odd way of doing things. | ||
Kfish
Chile282 Posts
I guess I reached an intermediate level, I understand inheritance, polymorphism, pointers to a certain extent (still can't figure out what the HEAP and STACK are lol), and I'm learning some SQL. I can see the differences in the languages and I'm starting to find out why one might be better than another for certain tasks. I'm really a newb though, haven't finished my first year at uni but I do read a lot and try to code a lot. I still can't manage to DO SOMETHING useful with this. I have no idea where to start making a name for myself besides the books. I've read, start contributing to open source. That sounds great! Where do I start? NO CLUE! haha I even started making a game engine with opengl tao framework in C# (until I realized the book I was reading has some fail to it). What do I need to do? ![]() I feel that there is so much to learn out there that I don't know what to focus on first. I mean, I realize I should be polishing my skills in one language instead of reading through and learning the basics/intermediate stuff for a whole bunch. Help is appreciated, I love programming and I want to learn it all... I could use some guidance. | ||
mmp
United States2130 Posts
On October 21 2011 04:48 tofucake wrote: Stuff is broken down into languages (or groups, ie HTML/CSS/Javascript). The particular section you read really depends on your interests. If you want to do website type things, HTML/CSS/Javascript are basically required (not so much Javascript). Actual programming in terms of web stuff will likely be PHP, ASP (.Net in general), or Perl. On the other hand, if you want to do programming you're going to want to focus more on a "traditional" language, typically of the C family (or Java if you hate yourself). What? If you do your programming in Javascript, you can very easily share your code via HTTP. And it is very rare today to see websites that use little-to-no Javascript, even if it is often abused for shiny bullshit. Also, ASP is antiquated and .NET is baroque. If you want to do *modern* backend dev you should look into Django, Rails, JSP/Tomcat, or one of the many frameworks built on top of PHP. You have a lot of good alternatives when making a web server today, but PHP is probably the only legacy server-side language that is still relevant. | ||
Deleted User 101379
4849 Posts
On October 21 2011 05:06 sekritzzz wrote: Are all groups separate or is one group a prerequisite to doing the job of another group? I'm more or less interested in making programs which probably fall into the "C family". Should I learn other languages before going into it or can I nosedive in? Also is it feasible for me to do a daily job and attempt to learn all 3 or should I concentrate my efforts towards one thing? I get the feeling that when it comes to programming, its more efficient to stick to one thing due to its never ending possibilities of progress. There are lots of programmers who focus on one language and area, but every good programmer at least dabbles in other areas and learns other languages. Until recently, i made it my goal to learn one new language every year and it helped me a ton. By checking out other languages you often see your main language from a new perspective and find new ways to solve problems. I can't tell you how much i learned from only one day of dabbling with scheme about how wrong i was approaching problems previously, eventhough i was already fluid in about 10 programming languages before that. To start, i would recommend going with "easy" languages that get stuff done fast, i.e. PHP for web development, C# for GUIs and Javascript if you want to focus more on web design. | ||
sekritzzz
1515 Posts
| ||
redbrain
Northern Ireland117 Posts
![]() | ||
| ||