d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Make Me A Better Programmer - From Step 1
Prev12345656Next
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 3 2012 11:46pm
Quote (AbDuCt @ Jul 4 2012 12:45am)
I can call iriimii guy out and laugh at him <3


I don't need anyone to laugh or shit on anyone, least of all me.
Member
Posts: 4,541
Joined: Sep 15 2011
Gold: 10,391.00
Jul 3 2012 11:48pm
Nah, the guys who ask for entire projects offer to pay FG for it, even if most of them end up offering much less than what the work is worth (which is in most cases corrected anyway). At the end of the day, those guys are just cheating themselves, but it's easy FG for us!

I've said this before and I'll say it again: I carry no illusion that I or anybody else posts here for anybody's sake besides our own amusement (or in the above case, sometimes FG! which translates to amusement in a different form eventually). That I end up helping anyone is a pleasant but not necessary side effect. So long as helping you remains more amusing than laughing at you, you can reasonably expect that people will give you help. But if you make it the other way around...

(which, by the way, is why you have this backwards. you still seem to think that this is about you.)

This post was edited by irimi on Jul 3 2012 11:55pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 4 2012 12:13am
Quote (irimi @ Jul 4 2012 12:48am)
Nah, the guys who ask for entire projects offer to pay FG for it, even if most of them end up offering much less than what the work is worth (which is in most cases corrected anyway).  At the end of the day, those guys are just cheating themselves, but it's easy FG for us!

I've said this before and I'll say it again: I carry no illusion that I or anybody else posts here for anybody's sake besides our own amusement (or in the above case, sometimes FG! which translates to amusement in a different form eventually).  That I end up helping anyone is a pleasant but not necessary side effect.  So long as helping you remains more amusing than laughing at you, you can reasonably expect that people will give you help.  But if you make it the other way around...

(which, by the way, is why you have this backwards.  you still seem to think that this is about you.)


forgive my faith in humanity
Member
Posts: 4,541
Joined: Sep 15 2011
Gold: 10,391.00
Jul 4 2012 09:56am
Quote (Eep @ Jul 3 2012 11:13pm)
forgive my faith in humanity


look in the mirror :)
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 4 2012 12:38pm
Quote (irimi @ Jul 4 2012 10:56am)
look in the mirror :)


looking in mirrors is for hipsters


here is my finished code now:

Code
#include <iostream>
#include <iomanip>

using namespace std;

int main() {

   double x, rate, total = 0;

   cout << setprecision(2) << showpoint << fixed;

   cout <<"Please enter the rate of interest" << endl;

   while (cin >> rate) {
       if (rate < .01 || rate > .1)
           cout << "Please enter a percent between 1% and 10% please!" << endl;
       else break;
   }

   cout <<"Please enter some values"<< endl;

   while (cin >> x) {
       if (x<0)
           cout << "Negative number detected: Ignored." << endl;
       else {
           total += x;
           total *= 1+rate;
       }
   }

   cout <<"Your total is: $" <<  total  << endl;

   //double variables  means total might not be 100% accurate!!

   return 0;
}
Member
Posts: 7,409
Joined: Apr 8 2008
Gold: 2,249.30
Jul 5 2012 11:32am
Quote (Eep @ Jul 4 2012 01:38pm)
looking in mirrors is for hipsters


here is my finished code now:

Code
#include <iostream>
#include <iomanip>

using namespace std;

int main() {

   double x, rate, total = 0;

   cout << setprecision(2) << showpoint << fixed;

   cout <<"Please enter the rate of interest" << endl;

   while (cin >> rate) {
       if (rate < .01 || rate > .1)
           cout << "Please enter a percent between 1% and 10% please!" << endl;
       else break;
   }

   cout <<"Please enter some values"<< endl;

   while (cin >> x) {
       if (x<0)
           cout << "Negative number detected: Ignored." << endl;
       else {
           total += x;
           total *= 1+rate;
       }
   }

   cout <<"Your total is: $" <<  total  << endl;

   //double variables  means total might not be 100% accurate!!

   return 0;
}



Hey, just looked at this and had some observations. I haven't read through the all the posts, but it seemed like a flame-war for a bit. So, moving along....

The first while loop, while it would achieve your desired result, doesn't make sense to me. Here's how I would have done it:
Code
cin >> rate
while (rate < .01 || rate . 1) {
     cout << "Please enter a percent between 1% and 10% please!" << endl;
     cin >> rate.
}


In the second while loop, there is no break, creating yourself a nice little infinite loop. Here is what I would do:

Code
cout <<"Please enter some positive values (enter a negative value to stop)"<< endl;
cin >> x;
while (x > 0) {
     total += x;
     total *= (1 + rate);
     cin >> x;
}

What the loop needed was some sort of exit criteria, and since you only wanted positive values, make negative values your loop breaker. That's a fun term. Might have to learn to play an instrument and start a band called Loop Breaker.

This post was edited by joeshabadoo on Jul 5 2012 11:34am
Member
Posts: 4,541
Joined: Sep 15 2011
Gold: 10,391.00
Jul 5 2012 12:50pm
Quote (joeshabadoo @ Jul 5 2012 10:32am)
The first while loop, while it would achieve your desired result, doesn't make sense to me. Here's how I would have done it:

While cin loop is a common idiom in C++ programming.

Quote (joeshabadoo @ Jul 5 2012 10:32am)
In the second while loop, there is no break, creating yourself a nice little infinite loop.

It's not going to create an infinite loop because of how the while(cin) idiom works. When an EOF is parsed, cin returns false and the loop will break on its own.

This post was edited by irimi on Jul 5 2012 12:52pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 5 2012 01:25pm
Thanks for the posts.

The way our professor is grading these is he takes the a.out (the file you get after compiling) and runs it with input from another file. He told us that if we were testing the program, it is OKAY if we hit a special command combination in unix/vi (ctrl+d) to end the program. For his file, there are x values. Like


.1
10
233
455
-45
300



apparently after 300 the file knows to break itself.

I believe one of the next things we are learning is about eof/etc.


I have tested this code a few times for some weird things but haven't been 100% thorough yet.

edit edit: I wouldn't call it too much of a flame war. It was mostly me responding to eagle in a somewhat educated manner.

edit: here is a real question

should I use spaces between lines? Or is that a bad habit I should fix?

I just think things always look kinda clumped otherwise, especially with how many cin/cout statements I have to use for this course.

This post was edited by Eep on Jul 5 2012 01:31pm
Member
Posts: 279
Joined: Apr 11 2010
Gold: 1,486.00
Jul 8 2012 07:34am
Blank lines are a tool you can use to create code that is easier to read. You don't want to double-space your code, but putting important things (like return statements) in their own "paragraph" helps call them out, and grouping related statements into one "paragraph" makes it easier to scan over the code and see what it's doing.
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Jul 9 2012 07:56pm
Quote (PumblesMumbles @ Jul 8 2012 08:34am)
Blank lines are a tool you can use to create code that is easier to read. You don't want to double-space your code, but putting important things (like return statements) in their own "paragraph" helps call them out, and grouping related statements into one "paragraph" makes it easier to scan over the code and see what it's doing.


I see what you mean. Cool stuff. I will work on prettiness soon.


Anyways, learned about functions and suddenly a lot of things that didn't make sense before made sense now and some things that were far apart got tied together. Need more knowledge!

This post was edited by Eep on Jul 9 2012 07:58pm
Go Back To Programming & Development Topic List
Prev12345656Next
Add Reply New Topic New Poll