nuclearfroggy's Profile User Rating: -----

Reputation: 82 Whiz
Group:
Contributors
Active Posts:
167 (0.08 per day)
Joined:
04-August 08
Profile Views:
5,209
Last Active:
User is offline Jul 07 2014 02:38 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
50

Latest Visitors

Icon   nuclearfroggy has not set their status

Posts I've Made

  1. In Topic: Basic Arrays: Average, Stddev, Bubblesort

    Posted 17 Oct 2012

    Okay, this is because when you say x[i] you're saying the ith element of the array x. You're then passing this to average(), but average() doesn't want an integer, it wants an array of integers. What you meant was:
     double avg = average(x, SIZE); 
    

    By just using the array name you pass a pointer to the first element in the array. You should also check out some tutorials on pointers and arrays while you're at it. :)
  2. In Topic: READING .CSV TO 2D VECTOR

    Posted 17 Oct 2012

    You aren't calling getline correctly. The first argument should be an input stream ie istream or ifstream, not ostream or ofstream. So it should be ifstream myFile. Next, you need to specify a string to store the read in input in. You should specify a string to store the temporary read in data. With the third argument you've said the delimiter should be the comma character. Check here for how to use getline.

    I'm not entirely sure what you're trying to do with line 34, that syntax isn't right though. You're trying to assign a string to a float value, and the constructor for string doesn't look right.

    Sorry I can't help any more, could you give us an example a file that you'd read in?
  3. In Topic: Basic Arrays: Average, Stddev, Bubblesort

    Posted 17 Oct 2012

    Your problem is coming from a bit of a misconception. In short, the error says that you're trying to return a function pointer when it expected a double. This might be a bit beyond what you've done, but the important bit is the fact you've declared your function "double average" doesn't mean you've got a double variable called "average". You've got a function (called "average") that returns a double value.

    The simple fix is to create a variable to store the value and return that. For example, for the average function this should work:
    //average
    double average(int x[], int SIZE)
    {
      double avg, total = 0.0;
      int i;
      
      for (i=0; i < SIZE; i++)
      {
        total += x[i];
      }
      avg = total / (SIZE-1);
      
      return avg;
    }
    

    Hope you've seen where you went wrong, if you need any clarification please say!
  4. In Topic: error C2082: redefinition of formal parameter 'price'

    Posted 29 Aug 2012

    Here the compiler's pretty much told you what's wrong, and should give you a line number which will direct you to the problem. In the parameter list of the function "calculate", one of the parameters is the float "price". You then below define another float called price. This is probably not what you intended, and you can't declare two variables with the same name (in the same scope).

    It seems as though you set the price in the function calculate, so you don't really need to pass the price at all. You've also made the return type of the function a float, but you're not really returning anything (just 0). I'm guessing you'll want to return the calculated value sum, which you would do by saying
    return sum;
    


    Your indentation is not very consistent or readable. Try and find a recognised style and stick to it. An IDE like Code::Blocks or Visual Studio, or even editor like Notepad++ will make it less painless (if you're not already using an IDE)

    Finally, if I'm going to be nitpicky ;) you've used "void main(void)", but main should have an integer return type, so use "int main(void)" or "int main(int argc, char *argv[])". Finally, in the function prototypes (lines 3 and 4) you need to specify the types of all the parameters (you can also include the names if you want). For example, as your code is currently, you'd have
    float calculate(float, float, float);
    

    Hope this helps.
  5. In Topic: Not sure where i went wrong!

    Posted 16 Aug 2012

    The indentation thing might seem trivial but it stops you making mistakes, and makes the code much more readable. If you have an IDE like Code::Blocks or Visual Studio then it shouldn't be too hard to keep code properly indented. One thing that might be confusing is all the different styles and which one is the right one. You realise eventually though the style used doesn't matter so much, but you have to use the same style consistently.

    After running your code through Visual Studio's indenter this came out:
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <ctime> 
    #include <time.h>
    
    
    using namespace std;
    
    
    using std::cout;
    using std::cin;
    using std::endl; 
    
    
    // variables in the game. 
    
    int player1turn (int) ;
    int player2turn (int) ;
    
    int diceroll (); 
    const int winscore= 100; 
    
    int main ()
    
    {
    	srand (time (NULL));
    	int player1score = 0 ;
    	int player2score = 0 ; 
    
    	do 
    	{
    		player1score = player1score + player1turn( player1score );
    
    		cout << " Player 1 total score is " << player1score << endl;
    
    		if ( player1score >= winscore ) 
    		{
    			cout << "Player 1 has won !! " ;
    			return 0;
    		}
    		player2score = player2score + player2turn(player2score) ;
    		cout << "PLayer 2 total score is " << player2score << endl;
    
    		if ( player2score >= winscore)
    		{ 
    			cout<< "PLayer 2 has won !! ";
    			return 0;
    		}
    	}
    
    	while ( player1score < winscore && player2score < winscore);
    }
    
    
    
    
    //The code for the game- allows players to roll the dice and gives them the option to hold or roll again
    //Also holds their score
    
    int player1turn (int player1score) 
    {
    	int thisscore= 0 ;
    	int	roll= 0;
    
    	char rOh;
    
    	do
    	{
    		roll = diceroll () ;
    		if (roll == 1 )
    		{
    			cout << "You have rolled a 1. It's the end of your turn " << endl;
    			return 0;
    		}
    		thisscore = thisscore + roll ;
    
    		cout << "You have rolled a " << roll << " . Your score so far is " << thisscore << endl;
    
    		do
    
    		{
    			cout << "Do you want to roll again (r) or hold (h) ? " ;
    			cin >> rOh ;
    
    		}
    		while (rOh == 'r' );
    		if ( rOh == 'h')
    			return player1score;
    	}
    
    
    
    	int player2turn (int player2score) 
    	{
    		int thisscore= 0 ;
    		int	roll= 0;
    
    		char rOh;
    
    		do
    		{
    			roll = diceroll () ;
    			if (roll == 1 )
    			{
    				cout << "You have rolled a 1. It's the end of your turn " << endl;
    				return 0;
    			}
    			thisscore = thisscore + roll ;
    
    			cout << "You have rolled a " << roll << " . Your score so far is " << thisscore << endl;
    
    			do
    
    			{
    				cout << "Do you want to roll again (r) or hold (h) ? " ;
    				cin >> rOh ;
    
    
    				while (rOh == 'r' );
    				if ( rOh == 'h')
    					return thisscore;
    			}
    
    			//Random dice generator
    			int diceroll () 
    
    			{
    				int roll ;
    
    				roll = ( rand () % 6 ) +1 ;
    			}
    
    
    It shows pretty clearly what's up. There are lots of curly braces not matching up, so functions are being defined in other functions and the file ends with some braces not matched up.

    Another little recurring problem is in do-while loops the while bit is in the wrong place. The while statement goes after the closing curly brace of the do loop. Hope this helps.

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Interests:
Rock Climbing, Tennis
Programming Languages:
C++

Contact Information

E-mail:
Private
Website URL:
Website URL  http://programmingnotesblog.blogspot.com/

Friends

Comments

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