Thread: Grrr this stuff is still new to me

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    3

    Angry Grrr this stuff is still new to me

    So I'm still getting used to this programming thing and i can't figure this out so I run here for help. If you choose to help me Thank you in advance
    heres the code
    Code:
    #include <iostream>
    using namespace std
    
    int main(int, argc, char*, argv[])
    {   int num=0, sum=0, cnt=0, largest=0, negative=0;
        while (cin)
    	{ cnt ++;
          cin>>num;
    
    	  cout << "input"<<num<<endl;
    	  sum=sum+num // or sum+=num;
          cout <<"sum="<<sum<<endl;
    	  if (num > largest)
    		  largest + num;
    	  if (num<0)
    		  negative++;//or negative=negative+1;
    	}
    	cout,,"largest="<<largest<<"negative="<<negative<<endl;
    	<<"sum="<<sum<<endl;
    	return 0;
    }
    and if you can suggest a good book to help me on my way that will also be much appreciated
    THANKS!

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Code:
    cout,,"largest="<<largest<<"negative="<<negative<<endl;
    	<<"sum="<<sum<<endl;
    Should be (semicolon, ,, should be <<):
    Code:
    cout << "largest=" << largest << "negative=" << negative << endl
            << "sum=" << sum << endl;
    And this:
    Code:
    using namespace std
    
    int main(int, argc, char*, argv[])
    Should be (semicolon, datatype name):
    Code:
    using namespace std;
    
    int main(int argc, char* argv[])

    A GREAT book is:
    The Complete Reference for C++ 3rd Edition
    By: Herbert Schildt

    Have fun and be careful with your semicolons!

  3. #3
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    Code:
    #include <iostream>
    using namespace std;
    
    int main(int argc, char* argv[])
    {
      int num=0, sum=0, cnt=0, largest=0, negative=0;
        while(cin)
    	{
         cnt++;
          cin>>num;
    
    	  cout<<"input"<<num<<"\n";
    	  sum=sum+num; // or sum+=num;
          cout<<"sum="<<sum<<"\n";
    	  if (num > largest)
          {
    		  largest + num;
          }
    	  if (num<0)
          {
          negative++;//or negative=negative+1;
          }
           
          }
     cout<<"largest="<<largest<<"negative="<< negative <<"\n"<<"sum="<<sum<<"\n";
    
    	return 0;
    }
    I hope the braces I added or my \n escape sequenced didnt confuse you there, btw: \n is newline.
    There you go!
    Last edited by civix; 02-09-2003 at 08:16 PM.
    .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 03:35 PM
  2. arguments, directories and stuff...
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 05:46 PM
  3. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM
  4. Linked lists and file i/o, and some other stuff
    By ninja in forum C++ Programming
    Replies: 9
    Last Post: 05-19-2002, 07:15 PM
  5. Stocks 'n' stuff...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 09-20-2001, 05:36 PM