C++ beginner assignement with loops

My assignement is to display in a console a while loop to calculate and display the sum of the numbers from 1 to 100,

This is my code:

// while loop.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
Console::WriteLine(L"TEST THE WHILE, FOR AND DO...WHILE LOOPS");
return 0;
//A while loop to calculate and display the sum of the numbers from 1 to 100

int i=1;
int sum=0;
while (i < 101)
{
sum += i;
i++;
}

This is the error message I got back and can't seem to figure out what my mistake is.
1>------ Build started: Project: while loop, Configuration: Debug Win32 ------
1>Compiling...
1>while loop.cpp
1>.\while loop.cpp(20) : fatal error C1075: end of file found before the left brace '{' at '.\while loop.cpp(8)' was matched
1>Build log was saved at "file://c:\Users\Marion\Documents\Visual Studio 2008\Projects\while loop\Debug\BuildLog.htm"
1>while loop - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
This isn't C++
 
(int i = 1, sum= 0);

You probably want:
1
2
int i = 0;
int sum = 0;
None of that is C++.
You should look for a C++/CLI forum.
I've updated the code but have 1 fatal error message. Help!
1
2
3
4
5
6
7
8
9
10
11
12
13
int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"TEST THE WHILE, FOR AND DO...WHILE LOOPS");
    return 0;

    int i=1;
    int sum=0;
    while (i < 101)
    {
        sum += i;
        i++;
    }
//No ending brace! 
Last edited on
It worked thank you sooo much, I'll now try the for loop. Thanks again
Topic archived. No new replies allowed.