Thread: Totally stuck where have i gone wrong??

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    Totally stuck where have i gone wrong??

    Hey all, currently i am doing this question
    Write a C++ program such that its execution will keep asking the user to enter a pair of integers, start and finish, and will terminate when either start>finish, or EOF or an invalid input has been encountered. Every time a new pair of integers start and finish are read, the program will first calculate the subtotal
    start2 + (start+1)2 + (start+2)2 + ... + (finish-1)2 + finish2and then add the subtotal to the total. Before the program terminates, it should display the accumulatedtotal and the average of all the subtotals.
    This is the code i have managed to get so get so far

    Code:
    #include <iostream>#include <cmath>
    // #include <string>
    using namespace std;
    
    
    int main()
    {
     double start, finish, subtotal, total, average;
     float a, b, c ;
     
     bool ValidInput = false;
    
    
    do
    {
       cout << "Enter the START and FINISH number: ";
       cin >> a, b ;
      
       c = pow(a , b);
    
    
       cout << a << "to the power of " << b << "equals to" << c
       << '_' << endl << endl;
    
    
    if (cin.fail() || start < finish)
    {
    cin.clear();
    cin.ignore();
    return 0;
    
    
    }
    else
    {
    double total;
    total = start + finish;
    
    
    cout << "The Subtotal Is : " << subtotal << endl;
    cout << "The Total Is: " << total << endl;
    cout << "The average is: " << average << endl;
    }
    
    
    } while ( ValidInput == false );
    
    
    system ("pause");
    return 0;
    
    
    }

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    A wild guess is that you're quite new to c++. The one on one is, debug. Use cout, printf() flush could be used too, to display your variables as you go along. So, first lesson: debugging and some brute force.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    response to thread

    yes i am quite new to c plus plus and been thrown into the deep end.
    where am i supposed to do the de bugging? e.g cout print f ()

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    Quote Originally Posted by überfuzz View Post
    A wild guess is that you're quite new to c++. The one on one is, debug. Use cout, printf() flush could be used too, to display your variables as you go along. So, first lesson: debugging and some brute force.
    It is ok to use a few output statements as a basic ' debug ' but you really shouldlearn to use the actual debugger that it is assumed you have also in your toolchain, so you can run the program in debug mode and watch the variables changing, step through the program a line at a time etc. What do you write your code and build with? IDE like code:blocks? please don't say turbo c !
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    3

    Reposnse to rogster

    I use dev c ++ how do i get the debugging mode set up?
    I just looked at the code again and think it is best to rewrite it again any tips to get me started off.

  6. #6
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    I thought i had replied to this but it seems my response has disappeared. Anyway, I said do not use Dev C++ as it is no longer up to date, get code blocks 10.05 or similar. i dont know what the debug key is in dev++ but you will find it by looking at the options in the menu bar. Also you will probably need your program to be in a project for the debugger to work, ie that you are not just making a single new file and then compiling it and running it.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    Quote Originally Posted by rogster001 View Post
    I thought i had replied to this but it seems my response has disappeared.
    Dude, you're obviously helping a newbie here. I guess your sarcasm will score better if you try it later on.

  8. #8
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    Quote Originally Posted by geekified View Post
    I just looked at the code again and think it is best to rewrite it again any tips to get me started off.
    There are many ways of planing a program. I always go with a piece of paper and a pen. Try to find out what works best for you.

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    ?

    Quote Originally Posted by überfuzz View Post
    Dude, you're obviously helping a newbie here. I guess your sarcasm will score better if you try it later on.
    - Dude - there was no sarcasm, I honestly meant I went back to view the post and the reply did not seem to have been added, I would not bash a newbie that shows code and effort, I have certainly been there myself too rite, so keep it in your pants next time before dishing out .
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    Quote Originally Posted by rogster001 View Post
    - Dude - there was no sarcasm, I honestly meant I went back to view the post and the reply did not seem to have been added, I would not bash a newbie that shows code and effort, I have certainly been there myself too rite, so keep it in your pants next time before dishing out .
    Pfft! I pretty sure you could feel the warm tenderness in my post.

  11. #11
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    The original poster may not have, and thought i was bashing after your comment is all, me piro vampiro.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. totally lost.
    By ain in forum C Programming
    Replies: 12
    Last Post: 02-06-2011, 05:12 AM
  2. Replies: 3
    Last Post: 09-06-2009, 01:48 PM
  3. Can someone help me im totally stumped
    By Joe123 in forum C++ Programming
    Replies: 2
    Last Post: 10-18-2005, 12:17 PM
  4. i'm totally lost
    By jlmac2001 in forum C++ Programming
    Replies: 5
    Last Post: 02-01-2003, 11:06 PM
  5. I am totally PuZZelEd
    By rahat in forum C Programming
    Replies: 2
    Last Post: 11-22-2001, 10:13 AM