Thread: Not sure where the mistake is coming from?

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

    Not sure where the mistake is coming from?

    Copied exactly from the book:

    Code:
    #include<iostream>
    #include<iomanip>
    #include<array>
    using namespace std;
    
    
    int main(){
        
        const size_t responseSize{20};
        const size_t frequencySize{6};
        
        const array<unsigned int, responseSize> responses{1, 2, 5, 4, 3, 5, 2, 1, 3, 1, 4, 3,3, 3, 2,3, 3, 2,2, 5};
        
        array<unsigned int, frequencySize> frequency{};
        
        for (size_t answer{0}; answer < responses.size(); ++answer){
            ++frequency[responses[answer]];
        }
        
        cout << "Rating"  << setw(12)  << "Frequency"  << endl;
        
        for (size_t rating {1}; rating < frequency.size(); ++rating){
            cout << setw(6)  << rating  << sets(12)  << frequency[rating]  << endl;
        }
        
    }
    Says setw is not given a value or something. As you can see...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,351
    What is the exact error message?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by laserlight View Post
    What is the exact error message?
    I can't tell because I reconfigured codeblocks without knowing what I exactly did. Meaning the error box is gone and I can't put it back where it used to be.

  4. #4
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    ||=== Build file: "no target" in "no project" (compiler: unknown) ===|
    C:\Users\\Documents\7chapterex2.cpp||In function 'int main()':|
    C:\Users\\Documents\7chapterex2.cpp|22|error: expected ';' before '{' token|
    C:\Users\\Documents\7chapterex2.cpp|22|error: expected primary-expression before '<<' token|
    C:\Users\\Documents\7chapterex2.cpp|22|error: 'sets' was not declared in this scope|
    C:\Users\\Documents\7chapterex2.cpp|22|note: suggested alternative: 'gets'|
    ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,069
    F2 closes and opens the log windows in Code::Blocks if I recall correctly.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by stahta01 View Post
    F2 closes and opens the log windows in Code::Blocks if I recall correctly.

    Tim S.
    Yes, I did a brief google search and had logs unchecked.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    4,069
    Is "sets(12)" supposed to be "setw(12)"
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  8. #8
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by stahta01 View Post
    Is "sets(12)" supposed to be "setw(12)"
    Yes.

  9. #9
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by stahta01 View Post
    Is "sets(12)" supposed to be "setw(12)"
    still didn't work.

  10. #10
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Thank you, I figured it out. { wrong bracket it was meant to be a (

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,351
    Ok, so you fixed an error, but you're still having an error now. What is your current code and the exact error message?

    Don't just say "still didn't work" without providing such an update, otherwise I'll just retort "then fix it!"
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #12
    Registered User
    Join Date
    Dec 2019
    Posts
    69
    Quote Originally Posted by laserlight View Post
    Ok, so you fixed an error, but you're still having an error now. What is your current code and the exact error message?


    Don't just say "still didn't work" without providing such an update, otherwise I'll just retort "then fix it!"
    No, baby please! I found the error and I fixed it and now the code is working the way it should.

    Code:
    #include<iostream>
    #include<iomanip>
    #include<array>
    using namespace std;
    
    
    int main(){
    
    
        const size_t responseSize{20};
        const size_t frequencySize{6};
    
    
        const array<unsigned int, responseSize> responses{1, 2, 5, 4, 3, 5, 2, 1, 3, 1, 4, 3,3, 3, 2,3, 3, 2,2, 5};
    
    
        array<unsigned int, frequencySize> frequency{};
    
    
        for (size_t answer{0}; answer < responses.size(); ++answer){
            ++frequency[responses[answer]];
        }
    
    
        cout << "Rating"  << setw(12)  << "Frequency"  << endl;
    
    
        for (size_t rating {1}; rating < frequency.size(); ++rating){
            cout << setw(6)  << rating  << setw(12)  << frequency[rating]  << endl;
        }
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help coming up with an answer
    By burnsidex in forum C Programming
    Replies: 2
    Last Post: 09-02-2013, 09:38 PM
  2. my second coming
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-17-2007, 09:54 AM
  3. My C++ test is COMING!!...
    By [Z-D] in forum C++ Programming
    Replies: 52
    Last Post: 12-01-2006, 08:02 PM
  4. Where are all these errors coming from?
    By Tride in forum C++ Programming
    Replies: 5
    Last Post: 08-24-2004, 09:37 AM
  5. Job Interview Coming Up
    By adamg in forum C Programming
    Replies: 5
    Last Post: 05-02-2004, 11:25 PM

Tags for this Thread