Confused about some C++ programs

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 3
Reputation: mattb_25 is an unknown quantity at this point 
Solved Threads: 0
mattb_25 mattb_25 is offline Offline
Newbie Poster

Confused about some C++ programs

 
0
  #1
Oct 4th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: Confused about some C++ programs

 
0
  #2
Oct 4th, 2007
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.
Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.

by Robert Frost the "The Road Not Taken"
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 3
Reputation: mattb_25 is an unknown quantity at this point 
Solved Threads: 0
mattb_25 mattb_25 is offline Offline
Newbie Poster

Re: Confused about some C++ programs

 
0
  #3
Oct 4th, 2007
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.. :\
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Confused about some C++ programs

 
0
  #4
Oct 4th, 2007
>>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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 3
Reputation: mattb_25 is an unknown quantity at this point 
Solved Threads: 0
mattb_25 mattb_25 is offline Offline
Newbie Poster

Re: Confused about some C++ programs

 
0
  #5
Oct 4th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,521
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1480
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Confused about some C++ programs

 
0
  #6
Oct 4th, 2007
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC