Friend's Challenge!!

Hello fellows!! So, my friend challenged me with this question and i have no clue how to do it but now i have a bet with him that i'll do it.. Please help me win the bet. The question is:

Write a program what uses the main function and a value producing function, DiffCheck, to accept one integer value after another from the keyboard until the absolute value difference between two successive inputs is greater than or equal to 15. DiffCheck will require the use of the absolute value library function, abs(), which is located in cstdlib.

Write a main function that asks the user to enter some integers. You will need to create logic where you can compare the number just entered with the number entered prior to the one just entered. You should use an indefinite do-while loop for this as we know we have to run the loop at least once. You are going to have to have a loop precondition to deal with the first input because you can’t compare it to anything. Inside the loop you advance the loop bounds by asking for the next input. In the conditional for the do loop you call the DiffCheck function which takes as arguments the latest input and the previous input. This loop should continue to ask for input until two successive inputs are 15 or more apart on a number line. As a loop post condition, output to the user: “The difference is greater [priorInput value] and [currentInput value] is greater than or equal to 15.”

The DiffCheck function has two integral arguments and returns a Boolean value. Important – a Boolean value is not an integer or any type of whole number - it is only the values true or false. The function evaluates the absolute difference between the two arguments. If the absolute difference is greater than or equal to 15, then DiffCheck function should return false. Otherwise, the DiffCheck function should return true. Hint: “evaluates the absolute difference” means do the subtraction using the abs() library function from cstdlib. For more information on the abs() function go to www.cplusplus.com and search on abs.

Using any of the following will drop your grade for this assignment by 70%

global variables (variables declared outside of all functions) use arguments to pass numbers!
cin in the DiffCheck function
cout in the DiffCheck function
goto statements anywhere
break or continue statements
Sample input and output when 1, 3, 6, -2 and -20 are input:

Enter some integers:
1
3
6
-2
-20
The difference between -2 and -20 is greater than or equal to 15.
Press any key to continue . . .
closed account (49iURXSz)

...function from cstdlib. For more information on the abs() function go to www.cplusplus.com and search on abs.

Using any of the following will drop your grade for this assignment by 70%

global variables (variables declared outside of all functions) use arguments to pass numbers!



Hello fellows!! So, my friend challenged me with this question and i have no clue how to do it but now i have a bet with him that i'll do it.. Please help me win the bet.


Why. Just why...

Just work on one part of the program's requirements at a time:


Write a main function that asks the user to enter some integers. You will need to create logic where you can compare the number just entered with the number entered prior to the one just entered. You should use an indefinite do-while loop for this as we know we have to run the loop at least once. You are going to have to have a loop precondition to deal with the first input because you can’t compare it to anything. Inside the loop you advance the loop bounds by asking for the next input. In the conditional for the do loop you call the DiffCheck function which takes as arguments the latest input and the previous input. This loop should continue to ask for input until two successive inputs are 15 or more apart on a number line. As a loop post condition, output to the user: “The difference is greater [priorInput value] and [currentInput value] is greater than or equal to 15.”

The DiffCheck function has two integral arguments and returns a Boolean value.


** Unrelated **

<ul>
<li>I wish</li>
<li>this forum supported</li>
<li>ordered and unordered lists...</li>
</ul>
Last edited on
It was his question but he failed it and i was roasting him for that that's why we had a bet cuz i thought i'll search it up and win the bet( i have never studied any computer language before) and he gave me the question as it was given to him... I am sorry but I am not a C++ student, I am actually a business student this was not my assignment.
.
Last edited on
closed account (49iURXSz)
This is a fairly complex question for someone who is a business student. Programming is basically Discrete Mathematics at its core; so work out the logic on paper first. Create an expression for determining if the difference in the absolute value for two numbers is greater than 15.

Then, you'll need to do some research on translating that logic into C++ code.
But I don't know anything about C++. I won't be able to convert it to C++. I mean you can send it to me in a private message if you don't want anyone to see the coding but it is just like Chinese to me. I don't even know how to write "A" properly. I am sorry for the disturbance.
closed account (49iURXSz)
It's not about whether anyone sees the code. That's what this forum is for; to help people learn. My concern now is why you took the bet without first understanding the scope of the problem you were trying to tackle.

If you really still want to go through with this, try looking at the following:

http://www.cplusplus.com/doc/tutorial/program_structure/ ( First C++ Program )
http://www.cplusplus.com/doc/tutorial/variables/ ( Store information )
http://www.cplusplus.com/doc/tutorial/operators/ ( Compare and Change Information )
http://www.cplusplus.com/doc/tutorial/basic_io/ (Get Information to the User and Show the User the Results)
http://www.cplusplus.com/doc/tutorial/control/ ( Decide What to Do with Information )
http://www.cplusplus.com/doc/tutorial/functions/ ( Changing Information Over and Over )
I am currently a high school student and a part time business student at community college and because of not having enough time i don't have a job too so i thought it would be a good way to make some money. P.S. I thought that i would search up whatever the question is on google like every thing else and get the answer. :)
closed account (49iURXSz)
Well at least you saw an opportunity and took a chance. Since you're getting into business, may I recommend taking a look at investing? One of my colleagues from my previous job does some side investing and he has learned several techniques from his personal business network to look for potential investing opportunities in the stock market. He also is an independent business owner for ACN. Check it out: http://tcabempire.acnrep.com/
Thanks for thinking for me and i'll definitely check it out but right now can you please help me make some money. ;)
Thanks bro.. I sure will :)
@printf if you try

#include <iostream>
#include <cstdlib>
using namespace std;

bool DiffCheck(int x, int y){

return(abs(x - y) >= 15) ? false : true;
}

int main(int argc, const char * argv[]) {

int latest, prior;

cout << "Enter some integers:\n";
cin >> prior;
cin >> latest;

while(DiffCheck(latest, prior)){
prior = latest;
cin >> latest;
}

cout << "The difference between " << prior << " and " << latest <<
" is greater than 15\nPress any key to continue ...\n\n";

return 0;
}
Topic archived. No new replies allowed.