| | |
Loop program help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2004
Posts: 18
Reputation:
Solved Threads: 0
Hi guys, having a little problem with my first c++ course and I'm hoping someone can help me out abit here.
Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, …50.
// this is the work I have so far.
#include <iostream>
using namespace std;
int main()
int getSum;
num;
{
if( num==1)
return 1;
else
return num+(getSum(num-1));
}
main
{
cout << "enter a number";
int value;
value=Console.ReadLine();
while(value<=0)
{
cout << "value has to be positive (>0). Enter
new value.";
value=ConsoleReadLine();
}
finalValue=getSum(value);
cout << "sum is: " + finalValue";
return 0;
}
I'm getting 2 error's and also I'm not sure if I've written this program correctly... very confused and my instructor at college being a first time instructor who unfortunately can't teach doesn't help things either
:mad:
Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, …50.
// this is the work I have so far.
#include <iostream>
using namespace std;
int main()
int getSum;
num;
{
if( num==1)
return 1;
else
return num+(getSum(num-1));
}
main
{
cout << "enter a number";
int value;
value=Console.ReadLine();
while(value<=0)
{
cout << "value has to be positive (>0). Enter
new value.";
value=ConsoleReadLine();
}
finalValue=getSum(value);
cout << "sum is: " + finalValue";
return 0;
}
I'm getting 2 error's and also I'm not sure if I've written this program correctly... very confused and my instructor at college being a first time instructor who unfortunately can't teach doesn't help things either
:mad:
Greetings wangstarr,
One thing I did notice with the provided source code was that there are a few errors, as you have stated:
Hope this helps,
- Stack Overflow
One thing I did notice with the provided source code was that there are a few errors, as you have stated:
int main(); // Ending in ; may stop the errors // Problem here: int getSum; num; // Changed int getSum(int num) { // Another Problem main { // Changed int main() {
Hope this helps,
- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.
IRC
Channel: irc.daniweb.com
Room: #c, #shell
IRC
Channel: irc.daniweb.com
Room: #c, #shell
![]() |
Similar Threads
- automatically insert code after every read and write inside a loop in a c program (Computer Science)
- Write a calculator program using a do-while loop (C++)
- trying to loop my program (C++)
- Need Help With A Loop Program!!!! (C++)
- C++ nest loop program - Help (C++)
Other Threads in the C++ Forum
- Previous Thread: displaying * in password entery
- Next Thread: Why doesn't my code work??
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist 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 temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





