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

Thread: help me with c++

  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,495

    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,495

    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
    5,113

    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. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. This post is public domain as specified at https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017

  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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,113

    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. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. This post is public domain as specified at https://creativecommons.org/publicdomain/zero/1.0/

    C, C++ Compiler: Microsoft VS2017

  9. #9
    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.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


HTML5 Development Center