CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    4

    help me with c++

    I need to find S and please explain how did you find S in N is 4

    #include <iostream>

    int main ()
    {

    int n,i,s;

    cout<<"Put the number of n"<<endl;
    cin>>n;

    s=0
    for (i=1;i<=n;i++)
    s=s+i
    cout<<"S is<<s<<endl;
    return 0
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: help me with c++

    What?

  3. #3
    Join Date
    Mar 2013
    Posts
    4

    Re: help me with c++

    I need to find S if N is 4...

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: help me with c++

    So what's your question? Run the program and input 4.

  5. #5
    Join Date
    Mar 2013
    Posts
    4

    Re: help me with c++

    #include <iostream.h>
    #include <stdlib.h>

    int main()
    {
    int n,i,s;
    cout<<"Insert number of n"<<endl;
    cin>>n;
    s=o;
    for(i=1;<=n;i++)
    s=s+i;
    cout<<"S is"<<s<<endl;
    system("PAUSE");
    return 0;

    I have 3 erors can anyone fix them?

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: help me with c++

    But before you can run it, you will need to fix the compile errors - particularly relating to missing ;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Mar 2013
    Posts
    4

    Re: help me with c++

    I fixed all missing ; but still 3 errors left....

    Anyone has idea where am i wrong?

    #include <iostream.h>
    #include <stdlib.h>

    int main()
    {
    int n,i,s;
    cout<<"Insert number of n"<<endl;
    cin>>n;
    s=o;
    for(i=1;<=n;i++)
    s=s+i;
    cout<<"S is"<<s<<endl;
    system("PAUSE");
    return 0;

  8. #8
    Join Date
    Feb 2013
    Location
    United States
    Posts
    56

    Re: help me with c++

    Quote Originally Posted by lopce View Post
    I fixed all missing ; but still 3 errors left....

    Anyone has idea where am i wrong?

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    	int n,i,s;
    	cout<<"Insert number of n"<<endl;
    	cin>>n;
    	s=0;
    	for(i=1;i<=n;i++)
    		s=s+i;
    	cout<<"S is"<<s<<endl;
    	system("PAUSE");
    	return 0;
    }
    If you want to learn C++, you need to understand the syntax of the language. These are simple errors that even a beginner should be able to find and fix easily.

    By the way, the answer is 10.

    S = (N * (N + 1)) / 2;

    Now write a program to find 12 + 22 + 32 + 42.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: help me with c++

    Code:
    #include <iostream.h>
    This is not standard ANSI c++. For standard ANSI c++ your headers should be

    Code:
    #include <iostream>
    #include <cstdlib>
    using namespace std;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured