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:

Edited by happygeek: fixed formatting

3
Contributors
2
Replies
4
Views
12 Years
Discussion Span
Last Post by h3rtz
0

Greetings wangstarr,

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

0

int value;
int num=1;
int sum=0;
while (num<=value) {

sum+=num;
num++;
}
cout <<"total is:" <<sum;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.