Thread: Jumping into C++ PracticeH Problem

  1. #1
    Registered User Sid_TheBeginner's Avatar
    Join Date
    Jun 2012
    Location
    India
    Posts
    19

    Exclamation Jumping into C++ PracticeH Problem

    Hello Guys. Please help me code this practice problem. Its from Alex Allain's Jumping into C++. A really cool book

    © Alex Allain (C programming.com - Learn C and C++ Programming - Cprogramming.com)
    Write a program that provides the option of tallying up the results of a poll with 3 possible values. The first input to the program is the poll question; the next three inputs are the possible answers. The first answer is indicated by 1, the second by 2, the third by 3. The answers are tallied until a 0 is entered. The program should then show the results of the poll—try making a bar graph that shows the results properly scaled to fit on your screen no matter how many results were entered.

    here's my code:
    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
    
        int reply;
        int one, two, three = 0;
        int step = 0;
    
        while(1)
        {
            cout << " What do you think of the\n"        
                    " Politician ABC?:\n"
                    " 1. Nothing, 2. He's an idiot!\n"
                    " 3. He's awesome!, 0. Get me outta here!!\n";
            cin >> reply;
    
            if(reply == 0)
            {
                    break;
            }
            if(reply == 1) one++;
        /*    if(reply == 2) two++;
            if(reply == 3) three++; */
                
        }
        
        cout << "Graph:\n";
    
        cout << " % .\n"; // trying to draw the Y-Axis
        cout << "20 .\n";
        cout << "15 .\n";
        cout << "10 .\n";
        cout << "05 .\n";
        cout << "00 .\t";
        
        step = 0; cout << "$";
        if(one <= 5 && one <= 9) step = 1; cout << "$";
        /*else if(one == 10) step = 2; cout << // m trying to plot a graph for only option 1. Hence this part is commented
        else if(one == 15) step = 3;
        else if(one = 20) step = 4;    
    
        if(step == 0) cout << "#\n"
        if(step == 1) cout << " */
    
        cout << "\nThanks for your input.\n"
                    "Press ENTER to quit.";
    
        cin.ignore();
        cin.get();
    }
    This one seems quite tough

    Thanks,
    Sid
    Last edited by Sid_TheBeginner; 11-18-2012 at 01:42 AM.

  2. #2
    Registered User
    Join Date
    Jan 2012
    Posts
    16
    Hello,
    First thing, you didn't even initialized one and two, cause
    Code:
    int one,two,three=0
    isn't equal to one=0,two=0,three=0,you just initialized three.
    While loop seems ok, i would only put some new lines in the pool quesiton. For the graph part, try using for loop, and also count how many times did while loop occured.

  3. #3
    Registered User Sid_TheBeginner's Avatar
    Join Date
    Jun 2012
    Location
    India
    Posts
    19
    I'm sorry for posting it like crazy I'll work on it more and ask more precise questions..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Jumping into C++ Chapter 5 problem 6 - Critique please
    By Kranky in forum C++ Programming
    Replies: 8
    Last Post: 03-07-2012, 05:44 PM
  2. Jumping to OOP in C++ from C
    By meadhikari in forum C++ Programming
    Replies: 6
    Last Post: 07-16-2010, 05:26 AM
  3. Jumping in the code...
    By AdampqmabA in forum C++ Programming
    Replies: 24
    Last Post: 10-06-2008, 05:34 PM
  4. Jumping between functions
    By Nexus-ZERO in forum C Programming
    Replies: 8
    Last Post: 01-14-2008, 03:47 AM
  5. Jumping Script
    By Krak in forum Game Programming
    Replies: 5
    Last Post: 01-12-2004, 03:19 PM

Tags for this Thread