944,204 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1355
  • C++ RSS
Apr 11th, 2006
0

I am lost. dont need homework done for me just a little help. have code.

Expand Post »
Hello all,

Thank you ahead of time if anyone answers this.
I am new to c++ and am having some difficulty understanding my assignment.
I wrote some code that does what the teacher has requested but according to her it does not utilize a function. I know that I have to call a function and that the function should not have to have user input to work but I don't really know how to modify my existing code to implement a function.
(I thought I was, as the program does what it is supposed to do, just not the way she wants it to be done.) PLEASE HELP!! HERE IS THE CODE I HAVE

#include <iostream>

using std::cout;
using std::cin;
using std::endl;


int reverse(); //function prototype for number reversal

int main() //begins program execution
{ int a; //number reversed
a = reverse();
cout << "The reversed number is " << a << endl; //final output


return 0; //end program
}

int reverse() //function
{
int x, y, z = 0; //initialize parameters

cout << "Enter an integer to be reversed: "; //initial number
cin >> x; //input number
while (x > 0){ //while conditions
y = x%10;
x = x/10;
z = 10 * z + y;
}
return z; //return value
} //end reverse function
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
totalnewb++ is offline Offline
4 posts
since Apr 2006
Apr 11th, 2006
0

Re: I am lost. dont need homework done for me just a little help. have code.

Quote originally posted by totalnewb++ ...
Hello all,

Thank you ahead of time if anyone answers this.
I am new to c++ and am having some difficulty understanding my assignment.
I wrote some code that does what the teacher has requested but according to her it does not utilize a function. I know that I have to call a function and that the function should not have to have user input to work but I don't really know how to modify my existing code to implement a function.
(I thought I was, as the program does what it is supposed to do, just not the way she wants it to be done.) PLEASE HELP!! HERE IS THE CODE I HAVE
It's a little unclear from your post exactly what you want to do -
If I understand you correctly, your teacher is asking for a function which will take the input as an argument, rather than from the user, something like this..
C++ Syntax (Toggle Plain Text)
  1. int reverse(int input)
  2. {
  3. // reversing algorithm here
  4. }
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Apr 11th, 2006
0

Re: I am lost. dont need homework done for me just a little help. have code.

this is the email I recieved from her:

the function should get its input from the parameter list, not directly from the user. For most functions, there shouldn’t be anything that deals with computer’s user interface such as keyboard or monitor. Please change this program and resend. Thanks.

Thank you for your help oh coded ones...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
totalnewb++ is offline Offline
4 posts
since Apr 2006
Apr 11th, 2006
0

Re: I am lost. dont need homework done for me just a little help. have code.

Quote originally posted by totalnewb++ ...
this is the email I recieved from her:

the function should get its input from the parameter list, not directly from the user. For most functions, there shouldn’t be anything that deals with computer’s user interface such as keyboard or monitor. Please change this program and resend. Thanks.

Thank you for your help oh coded ones...
This was just explained to you in the other post. Take a look at this example:
C++ Syntax (Toggle Plain Text)
  1. int reverse(int num) {
  2. int reverse = 0;
  3.  
  4. while (num > 0) {
  5. reverse *= 10;
  6. reverse += num % 10;
  7. num /= 10;
  8. }
  9. return reverse;
  10. }
Your method shouldn't prompt the user, but rather return the reverse of a number.

Hope this helps.

PS. I don't mind if you use that algorithm, but I'm sure your teacher will. Try to fix up your algorithm (they're pratically the same anyway).
Reputation Points: 32
Solved Threads: 10
Junior Poster in Training
destin is offline Offline
94 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: VC++: setting up columns and rows in a Datagrid
Next Thread in C++ Forum Timeline: xml file parsing in c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC