any1 can solve this

This is a discussion on any1 can solve this within the C++ Programming forums, part of the General Programming Boards category; Develop an interactive program that reads a low value, a high value, and an increment value, ensures that the low ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    3

    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

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    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.
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    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;    
    }
    Last edited by JimmyJones; 08-08-2008 at 07:03 AM.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,886
    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.

  6. #6
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    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

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    Quote Originally Posted by laserlight View Post
    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 View Post
    Incidentally, fflush(stdin) is undefined

    You are right. I am a novice, and I didn't realize. I will look for a better approach.
    Last edited by JimmyJones; 08-07-2008 at 08:12 AM.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,886
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Quote Originally Posted by JimmyJones View Post
    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.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  10. #10
    Registered User
    Join Date
    Aug 2008
    Posts
    3
    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

  11. #11
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    Quote Originally Posted by laserlight View Post
    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)".
    Last edited by JimmyJones; 08-08-2008 at 07:44 AM.

  12. #12
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by JimmyJones View Post
    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.
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by JimmyJones View Post
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Aug 2008
    Posts
    15
    Quote Originally Posted by matsp View Post
    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...

  15. #15
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Quote Originally Posted by JimmyJones View Post
    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.
    Here to Deceive, Inveigle, Obfuscate Since 1945

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can anyone solve this for me? (look inside)
    By johnsonswww in forum C Programming
    Replies: 10
    Last Post: 03-02-2009, 10:24 AM
  2. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  3. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  4. How to handle in software to solve this block diagram?
    By vnrabbit in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:45 PM
  5. Help to solve this problem
    By Romashka in forum C++ Programming
    Replies: 3
    Last Post: 04-16-2002, 09:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21