| | |
summation program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi everyone,
I am writing a summation program for a programming class I am taking. The assignment's main purpose is to give me practice writing functions. I have gotten the functions down just fine, but I can't seem to figure out how to write the inside of the summation function. The program asks for two long long ints; the start (which must be >= 1000), and then the howMany (which must be >250). then it passes these values to the summation function. According to the assignment sheet, the summation function simply adds all of the numbers from the starting value (start) up until the required number of values have been added together. Maybe this is just worded wrong for me to understand. Can anyone help me? I have posted the code I have done so far below. Thank you in advance.
Nick
I am writing a summation program for a programming class I am taking. The assignment's main purpose is to give me practice writing functions. I have gotten the functions down just fine, but I can't seem to figure out how to write the inside of the summation function. The program asks for two long long ints; the start (which must be >= 1000), and then the howMany (which must be >250). then it passes these values to the summation function. According to the assignment sheet, the summation function simply adds all of the numbers from the starting value (start) up until the required number of values have been added together. Maybe this is just worded wrong for me to understand. Can anyone help me? I have posted the code I have done so far below. Thank you in advance.
Nick
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; long long int summation(long long int start, long long int howMany); int main () { long long int s = 0; long long int h = 0; while (s < 1000) { cout << "Please enter the starting value: "; cin >> s; } while (h <= 250) { cout << "Please enter how many numbers to sum: "; cin >> h; } cout << "The summation of the numbers from " << s << " to " << h + s - 1 << " is " << summation(s,h) << endl; return 0; } /***************** * Function Name: summation * Paremeters: long long int start, long long int howMany * Return Value: long long int-sum * Description: this adds the numbers from the starting value up until * the required number of values have been added together. *****************/ long long int summation(long long int start, long long int howMany) { // SHOULD DO THE SUMMATION STUFF RIGHT HERE. return sum; }
•
•
Join Date: Jul 2005
Posts: 164
Reputation:
Solved Threads: 5
something like
C++ Syntax (Toggle Plain Text)
long long int summation(long long int start, long long int howMany) { long long sum=0; for(long long i=0,j=start;i<howMany;++i,++j) sum += j; return sum; }
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- Grade program (C)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Please Help With Bisection Method! (C++)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Noobie, can someone help?
- Next Thread: number format exceptions
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





