# any1 can solve this

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 08-06-2008
ajoi24
any1 can solve this
Develop an interactive program that reads a low value, a high value, and an increment value, ensures that the low value is less than or equal to the high value, and computes and prints a table of square and cube values from low to high at increments of increment.

Sample input-output :

Low value : 1
High value : 5
Increment : 1

Value Square Cube
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125

ill try 2 do it but still cant solve it..by da way im new to c++..so help me
• 08-06-2008
matsp
Anyone with a rudimentary knowledge of C++ can solve that, yes. You need to work out how to solve it, and we will help you in that process, but we don't give you the answer, as this is not the "We do your homework for you" website, but rather one that offers help and answers to direct questions.

How far have you got so far? Can you input the numbers? Can you perform the loop to produce the basic numbers (1..5 in the first column in your code)?

--
Mats
• 08-06-2008
SlyMaelstrom
Alright, so you've got a read statement, a conditional statement, a for loop, a few arithmetic calculations followed by a write statement. Not too bad...

Familiarize yourself with <iostream> and its cin and cout stream objects. Then read up on if statements and for loops. ... and if you don't know math, I'd read up on how exponents work. That's about all there is to it.
• 08-07-2008
JimmyJones
Here ya go buddy. I'm assuming this is not homework...

Code:

```#include <iostream> using namespace std; void findSquareCube(int LowValue, int HighValue,int Increment) {     int memLowValue = LowValue;         while(memLowValue <= HighValue)     {         LowValue = memLowValue;                cout << LowValue << "  ";                 LowValue *= LowValue;              cout << LowValue;             LowValue *= memLowValue;            cout << "  " << LowValue << "\n";         memLowValue += Increment;     } } int main() {     int LowValue=0;     int HighValue=0;     int Increment=0;           cout <<"\n\nEnter high value  ";     cin >> HighValue;         cout << "Enter low value  ";     cin >> LowValue;     while(LowValue > HighValue)     {         cout << "\nSorry, but low value must be less than or equal to high value.\n"                 "Please enter low value again  ";         cin >> LowValue;                      }       cout <<"\n\nEnter Increment value  ";     cin >> Increment;           findSquareCube(LowValue, HighValue, Increment);       /*Don't be confused by these next 9 lines of code they are just to pause the program before termination - no big deal... */     cout << "\n\n\nPress enter to EXIT program...";        int ch;     if(cin.peek() < 0)     {         while ( (ch=cin.get()) != EOF && ch != '\n' );                }         cin.get();  return 0;    }```
• 08-07-2008
laserlight
Quote:

I'm assuming this is not homework...
I am assuming that you are so blind as not to recognise a homework question when you see it. Incidentally, fflush(stdin) is undefined, but I cannot figure out why you want to use it in this context considering that this is C++ and the C I/O functions are unnecessary here.
• 08-07-2008
Stonehambey
The members of this board aren't obliged to help you, but they do so anyway. I've found this to be an invaluable resource for times when I have gotten stuck on concepts, locating errors etc.

With this in mind, it really saddens me to see OPs like this, a simple "please" and "thank you" is not hard and goes a long way to show you actually appreciate the time people put in to replying to questions.

This post is probably misplaced, but I see threads like this so often that eventually I had to say something :P
• 08-07-2008
JimmyJones
Quote:

Originally Posted by laserlight
I am assuming that you are so blind as not to recognise a homework question when you see it.

Well this guy could easily just be a complete beginner, and not a student, who is looking for help. And I know that beginners just love examples, and no doubt need them, and even if he is a student, I am sure that answering just one simple question is not going to jeopardize his career as a computer programmer. Now if he keeps asking questions like this, then I can see the problem that you imply.

Quote:

Originally Posted by laserlight
Incidentally, fflush(stdin) is undefined

You are right. I am a novice, and I didn't realize. I will look for a better approach.
• 08-07-2008
laserlight
Whether ajoi24 is a beginner in his/her free time or a student in an academic institution, this is a homework question. Spoonfeeding without any attempt on ajoi24's part does more harm than good. This is why matsp asked questions like "How far have you got so far? Can you input the numbers? Can you perform the loop to produce the basic numbers (1..5 in the first column in your code)?" The idea is to guide ajoi24 to making an attempt, and only if this genuine attempt fails (or can be improved) then a "model answer" should be provided.
• 08-07-2008
indigo0086
Quote:

Originally Posted by JimmyJones
Well this guy could easily just be a complete beginner, and not a student. And I know that beginners just love examples, and no doubt need them, and even if he is
a student, I am sure that answering just one simple question is not going to jeopardize his career as a computer programmer. Now if he keeps asking questions
like this, then I can see the problem that you imply.

Once you turn in a problem that someone else gave you, you made the wrong step in the direction of your programming career.

One thing programmers should exercise is the ability to learn concepts and apply them to a problem, not learn the solution to the problem by reading the solved solution.
• 08-07-2008
ajoi24
guys im tying to learn C++..so the best way is to do question based on real question..this question i got it from my friend..thanks for giving me answer but all i need is more on guidline....i have 0 exp on C++...so i really2 appreciate all help from your guys....thanks a lot..im gonna try it based on what u guys told me and hopefully i can do my own program...thanks alot
• 08-07-2008
JimmyJones
Quote:

Originally Posted by laserlight
and only if this genuine attempt fails (or can be improved) then a "model answer" should be provided.

Can't argue with that logic... but having gone through some of the post here I was under the impression that the people on this board would never ever give a "model answer".

EDIT: This is actually an edit to post #4, it is no longer editable, and I didn't want to create another post. "if(cin.peek() < 0)" should be "if(cin.peek() > 0)".
• 08-07-2008
QuantumPete
Quote:

Originally Posted by JimmyJones
I was under the impression that the people on this board would never ever give a "model answer".

And what does that tell you? Do you think that every single programmer on these boards is mean? In programming, more than anywhere else, it's important to be "learning by doing".

QuantumPete
P.S. I also think that this is a homework question and if the OP's story is really true, then starting on a problem like that with "zero C++ experience" is just plain dumb.
• 08-07-2008
matsp
Quote:

Originally Posted by JimmyJones
Can't argue with that logic... but having gone through some of the post here I was under the impression that the people on this board would never ever give a "model answer".

Well, it partly depends on the actual question asked, and partly on the effort shown by the poster. I certainly have posted answers. But as you can probably understand, "learning to copy from the web" is not "learning to program". Providing a correct answer to someones homework simply provides the learning to copy from the web, not understanding of the process of how to program - which is something the original poster probably is trying to do [the fact that said person may have spent 3 days out of 4 days playing Quake/getting drunk/etc instead of working on the code, and is now in a desperate panic is not really an excuse for us - if it's a VALID excuse, bring it up with the tutor - if it's a lame excuse, then the poster may fail the class - which is probably better for most purposes than passing based on someone else's work].

--
Mats
• 08-07-2008
JimmyJones
Quote:

Originally Posted by matsp
Well, it partly depends on the actual question asked, and partly on the effort shown by the poster. I certainly have posted answers. But as you can probably understand, "learning to copy from the web" is not "learning to program".

Good response matsp. You seem to be more understanding than some other people. I geuss this is why your answer here is good, and once again, can't argue with that logic...
• 08-07-2008
indigo0086
Quote:

Originally Posted by JimmyJones
Good response matsp. You seem to be more understanding than some other people. I geuss this is why your answer here is good, and once again, can't argue with that logic...

It's well understood for most people here that if you want help, first read the rules, then post the question and some code to show that you did effort (a code shell given by a teacher is not effort), then you'll probably get some code to assist you. Or you can ask for elaboration on concepts or theory, that ususally goes better than "here's problem, gimme answer".

I'd advise the OP to learn the syntax, learn about the OO concepts, and then attempt to code.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last