sungchoiok's Profile User Rating: -----

Reputation: 44 Craftsman
Active Posts:
141 (0.07 per day)
18-July 10
Profile Views:
Last Active:
User is offline Jun 16 2014 04:52 PM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
Icon   sungchoiok has not set their status

Posts I've Made

  1. In Topic: I need some help in array as a function argument by reference program

    Posted 23 Feb 2014

    Have you figured out the reason yet? Because the reason is... really simple.

    getGrades(grades, size);
    getTotalAver(grades,aver3, size);

    getTotalAver writes to aver3
    but showaverage uses aver2.

    Anyway, considering that your problems are now all fixed, I'll just give you a quick advice:
    Take a few seconds and format your code nicely; people will love you even more.
    void getGrades(double grades1[], const int &i)
        for (int index=0; index<i; index++) {
            cout << "Enter grades";
            cin  >> grades1[index];            
    void getTotalAver(double numbers[], double &aver, const int &SS)
        double total = 0.0;
        for(int count=0; count<SS; count++) {
            total += numbers[count];
        aver = total/2.0; //< almost forgot to tell you -- take the average OUTSIDE of the loop.
  2. In Topic: Help creating a class composition

    Posted 23 Feb 2014


    I don't know how to start / create this .cpp file to define the variables.


    I'm assuming that you don't know what to do about the .cpp file at all...? since you said you don't know how to "define the variables"?

    View PostzygzagX, on 22 February 2014 - 09:50 PM, said:

    #include <iostream>
    using namespace std;
    class NumDays
       double hours;
       double days;
       NumDays(double h);
       void setHours(double h);
       double getHours() const; 
       void setDays(double d);
       double getDays() const;

    What you have above is a fine header file. To implement the *.cpp file, you do something like this:

    #ifndef NUMDAYS_H // <-- must put the header guards.
    #define NUMDAYS_H
    #include "numdays.h"  // <-- #include the header file here so this cpp file knows what everything in here is referring to. Of course, this works assuming that the header file you created is named "numdays.h".
    void NumDays::setHours( double h ) // <-- this is an example of how to implement the member function declared in "numdays.h".
        hours = h;
        days = //whatever formula to calculate the days from the hours.
    #endif <-- endif for the header guards above.

    Now that you have numdays.cpp and numdays.h, you can use the class now from main.cpp by putting #include "numdays.h" and using the class like always.

    Hope that helped and I understood your question correctly.
  3. In Topic: this yes or no loop is not working i need help

    Posted 23 Feb 2014

    By "not working right," you are meaning right after the calculation, the program outputs "would you like another calculation?" and quits instead of waiting user input, right? I compiled your code and that's what it did on my computer.

    The problem is not your loop. Your loop works fine. It's just that the second scanf is not awaiting the user command for some reason.

    I have to go somewhere right now. Just visit the site that I linked in the post above and I'll answer later if you don't get it.
  4. In Topic: this yes or no loop is not working i need help

    Posted 23 Feb 2014

    First of all: Forum Rules

    A more descriptive problem statement than "it's not working" would help. (:

    But I'll be nice... I compiled the code and found out what the problem is. It's that the second scanf doesn't stop and wait for the user input.

    I work with C++, so it's been ages since I used scanf or anything like that, so I didn't know why it behaved that way at first. However, I typed "scanf doesn't wait" in Google and found this.

    Hope that helps. Also hope I demonstrated that Google is your friend. (;
  5. In Topic: New to the game - stuck on accumulating the de-incrementing points

    Posted 22 Feb 2014

    Look at line 100 and line 101, line 185 and line 186 in functions playerStrike() and computerStrike():
    int computerHealth = 100,
    playerHealth = 100,

    You are telling the computer to set computerHealth and playerHealth to 100 every time the function is called. This is why the health (and probably all the other status variables) are constantly being set to the original value.

    The quick solution is to make the variables global. If you don't know how to do that, feel free to ask.
    There's a better way of structing the state variables passing references of it to the functions but I don't know if I should go into that.

    	    const int   MAX_RANGE = 100,
    	                COMPUTER = 1,
    	                PLAYER = 2,
    	                CANON = 1,
    	                GRENADE = 2,
    	                RIFLE = 3,
    	                CANON_DAMAGE = 6,
    	                GRENADE_DAMAGE = 6,
    	                RIFLE_DAMAGE = 6;

    should be put outside of the functions in the global space. Otherwise, the computer re-allocates those variables every single time the function is called and that's quite inefficient. (the compiler might optimize it though, but that's beside the point.) But good job in making the variables constant!

    Also, are you using an IDE that has debugging capabilities? What are you using to program? Problems like these can be found very easily when you step through the code and track when the variables change.

My Information

Member Title:
D.I.C Head
20 years old
March 11, 1995
Years Programming:
Programming Languages:
c++, C, Visual Basic .NET

Contact Information

Click here to e-mail me



sungchoiok has no profile comments yet. Why not say hello?