| | |
I am lost. dont need homework done for me just a little help. have code.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
•
•
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
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)
int reverse(int input) { // reversing algorithm here }
•
•
Join Date: Apr 2006
Posts: 4
Reputation:
Solved Threads: 0
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...
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...
•
•
•
•
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...
C++ Syntax (Toggle Plain Text)
int reverse(int num) { int reverse = 0; while (num > 0) { reverse *= 10; reverse += num % 10; num /= 10; } return reverse; }
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).
![]() |
Similar Threads
- Google owes me money (Pay-Per-Click Advertising)
- please help me with this problem (C)
- C++ help ,am new to C++ ,PLZ Help ASAP (C++)
- Help With Contstructors (Java)
- Errors in My XP Error Log. (Windows NT / 2000 / XP)
- Preparing for an interview and need some questions answered (C)
Other Threads in the C++ Forum
- Previous Thread: Display Longest and Shortest Word in a String
- Next Thread: xml file parsing in c++
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





