Thread: Is codeblocks not reading the while statement or am I not doing it...

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    99

    Is codeblocks not reading the while statement or am I not doing it...

    ...the right way?

    Code:
    #include <iostream>using namespace std;
    int main()
    {
    int sum = 0, value = 0;
    while (cin>> value)
        sum += value;
        cout << "Sum is:"<< sum<<endl;
        return 0;
    
    
    
    
    
    
    
    
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Well since Code Blocks is just an IDE, it would suggest that you must be doing something wrong.

    Perhaps you might want to consider using Code Blocks auto indent feature to give you some hints since your current indent method is hiding some problems.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int sum = 0, value = 0;
        while(cin >> value)
            sum += value;
        
        cout << "Sum is:" << sum << endl;
    
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. If Statement, reading switches
    By Joel RD in forum C Programming
    Replies: 4
    Last Post: 05-01-2019, 07:30 AM
  2. Replies: 2
    Last Post: 12-09-2011, 10:57 AM
  3. using codeblocks
    By torquemada in forum Tech Board
    Replies: 7
    Last Post: 04-20-2011, 08:57 PM
  4. error with scanf statement in codeblocks
    By narendrav in forum C Programming
    Replies: 1
    Last Post: 03-19-2011, 11:25 AM
  5. reading file then if statement not working
    By patrink in forum C Programming
    Replies: 3
    Last Post: 12-17-2010, 01:48 AM

Tags for this Thread