944,044 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 762
  • C++ RSS
Oct 4th, 2007
0

Confused about some C++ programs

Expand Post »
Hey guys, i need some help with 2 programs that my teacher assigned me..

I just cant seem to figure them out. I'll type out what the program is, but I really dont have much code to show since I dont really know how to even get started so any help would be welcomed..

The only part I really dont know how to do is the average part.

--------------------------------

1. Write a program that asks the usr for a positive integer value. The program should use a "while-loop" to get the sum of all the integers from 1 to the number entered.
Last edited by mattb_25; Oct 4th, 2007 at 5:53 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mattb_25 is offline Offline
3 posts
since Oct 2007
Oct 4th, 2007
0

Re: Confused about some C++ programs

Quote ...
1. Write a program that asks the usr for a positive integer value. The program should use a "while-loop" to get the sum of all the integers from 1 to the number entered.
post some code....

where did you get stuck?
tip:: you read a number and then you use it as as an "end" condition in a for loop
Last edited by n.aggel; Oct 4th, 2007 at 6:00 pm.
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006
Oct 4th, 2007
0

Re: Confused about some C++ programs

Here's all I got.. I just don't know how to find the sum of the numbers between 1 and the number they entered.. :\
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int num = 1;
  7. int picknum = 0;
  8.  
  9. cout << "Chose a positive number." << endl;
  10. cin >> picknum;
  11.  
  12. while (num ???)
  13. {
  14. cout << "The sum of the number 1 to your desired number = " << (num
Last edited by Ancient Dragon; Oct 4th, 2007 at 8:17 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mattb_25 is offline Offline
3 posts
since Oct 2007
Oct 4th, 2007
0

Re: Confused about some C++ programs

>>I just don't know how to find the sum of the numbers between 1 and the number they entered

How would you do it yourself with pencil & paper? If I enter 5 then you want 1+2+3+4+5. Now do the same thing with a loop and two counters -- one counter is a loop counter and the other variable is the sum of the value of the loop counter on each iteration of the loop.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Oct 4th, 2007
0

Re: Confused about some C++ programs

Would I use a count-controlled loop? I'm still trying to figure out how to use the loops and counters since I just learned about them in class so sorry for the newbie questions.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mattb_25 is offline Offline
3 posts
since Oct 2007
Oct 4th, 2007
0

Re: Confused about some C++ programs

Your instructions say you must use a while loop. You will need two integers, one to count from 1 to whatever number you enter, and the other to sum up the values. Do it a little bit at a time so that you don't get overwhelmed. First how to create that while loop. After you get that done then add the counter to count from 1 to N. Only after that works do you worry about the sum integer.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: urgent help postfix evaluation
Next Thread in C++ Forum Timeline: Ending a program...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC