| | |
Confused about some C++ programs
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Solved Threads: 0
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.
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.
•
•
•
•
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.
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"
by Robert Frost the "The Road Not Taken"
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Solved Threads: 0
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)
#include <iostream> using namespace std; int main() { int num = 1; int picknum = 0; cout << "Chose a positive number." << endl; cin >> picknum; while (num ???) { 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
>>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.
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.
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.
![]() |
Similar Threads
- unknown harddrive error (Windows NT / 2000 / XP)
- Web Graphic Programs....Design? (Graphics and Multimedia)
- Problem with unwanted programs (Windows 95 / 98 / Me)
- knowing which programs are needed and which arent (Windows 95 / 98 / Me)
- knoppix or else (Getting Started and Choosing a Distro)
- article on affiliate programs (Advertising Sales Strategies)
- What should I do against threats from the net? (Viruses, Spyware and other Nasties)
- Cannot access programs and more (Windows NT / 2000 / XP)
- a couple of windows ME questions... (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: urgent help postfix evaluation
- Next Thread: Ending a program...
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int integer java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






