GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Nov-2007, 21:42
dmb2140 dmb2140 is offline
New Member
 
Join Date: Oct 2007
Posts: 5
dmb2140 is on a distinguished road

C++ Function Trouble(I'm having trouble with my program).


C++,CPP

I'm having trouble tripleing my out put. The program works, but I'm having trouble figuring out how to triple the out put. I do have a function listed in my program as void triple(int & number_used), but it doesn't seem to effect the program at all. I need some help with this function. So far my out put looks like this.
Enter up to 10 nonnegative numbers.
Mark the end of list with neg number
1
2
3
4
5
Array Values ......
1 2 3 4 5 Press any key to continue . . .

I need help or guidence with getting the out put to triple its out put as in...
Enter up to 10 nonnegative numbers.
Mark the end of list with neg number
1
2
3
4
5
Array Values ......
3 6 9 12 15 Press any key to continue . . .

Here is my c++ code in cpp format.
C++,CPP

CPP / C++ / C Code:
#include <iostream>

void triple(int& number_used);
void fill_array(int a[], int size, int& number_used);


int main ()
{
    using namespace std;       
    int sample_array[5], number_used;    
    fill_array(sample_array, 5, number_used);      
        cout << "The array values are:\n";    
    for (int index = 0; index < number_used; index++)       
        cout << sample_array[index] << " ";    
        cout << endl;   
    system("pause");
    return 0;
}

void triple(int & number_used)
{
    number_used *= 3;
}


void fill_array(int a[], int size, int& number_used)
{    
    using namespace std;    
    cout << "Enter up to " << size 
         << " nonnegative whole numbers.\n"         
         << "Mark the end of the list with a neg number.\n";    
    int next, index = 0;    
    cin >> next;      
    while ((next >= 0) && (index < size))    
    {   
        a[index] = next;        
        index++;        
        cin >> next;    
    }    
    
    number_used = index;
}

//C++, CPP
End of code
Last edited by admin II : 25-Nov-2007 at 08:44. Reason: Please surround your C++ code with [cpp] your code [/cpp]
  #2  
Old 24-Nov-2007, 12:00
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 534
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: C++ Function Trouble(I'm having trouble with my program).


I could not find anywhere in your code where you actually call the function triple(). Call it like this:
CPP / C++ / C Code:
int a = 5;
triple(a);
cout << a;
  #3  
Old 25-Nov-2007, 10:27
knightstorm knightstorm is offline
New Member
 
Join Date: Nov 2007
Location: Murray, KY
Posts: 1
knightstorm is on a distinguished road

Re: C++ Function Trouble(I'm having trouble with my program).


Your problem is that you did not call the triple function in your code like the example here:

CPP / C++ / C Code:
#include <iostream>

void triple(int& number_used);
void fill_array(int a[], int size, int& number_used);


int main ()
{
    using namespace std;       
    int sample_array[5], number_used;    
    fill_array(sample_array, 5, number_used);      
        cout << "The array values are:\n";    
    for (int i = 0; i < 5; i++)
    {
         triple(sample_array[i]);
    }
    for (int index = 0; index < number_used; index++)       
        cout << sample_array[index] << " ";    
        cout << endl;   
    system("pause");
    return 0;
}

void triple(int & number_used)
{
    number_used *= 3;
}


void fill_array(int a[], int size, int& number_used)
{    
    using namespace std;    
    cout << "Enter up to " << size 
         << " nonnegative whole numbers.\n"         
         << "Mark the end of the list with a neg number.\n";    
    int next, index = 0;    
    cin >> next;      
    while ((next >= 0) && (index < size))    
    {   
        a[index] = next;        
        index++;        
        cin >> next;    
    }    
    
    number_used = index;
}
 
 

Recent GIDBlogStupid Management Policies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
return string from a function Howard_L C Programming Language 4 18-Aug-2007 00:56
floating point decimal to ascii conversion crazypal C Programming Language 5 18-Apr-2007 05:59
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 14:12
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 05:59

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.