int main () {
int throwOne,
throwTwo,
throwThree;
FirstThrow(throwOne);
SecondThrow(throwTwo);
ThirdThrow(throwThree);
FindErrors();
return 0;
}
void FirstThrow(int throwOne) {
cout << "Enter the first score: ";
cin >> throwOne;
return;
}
void SecondThrow(int throwTwo) {
cout << "Enter your second score: ";
cin >> throwTwo;
return;
}
void ThirdThrow(int throwThree) {
cout << "Enter your third score: ";
cin >> throwThree;
return;
}
void FindErrors(){
int throwOne,
throwTwo,
throwThree;
if (throwOne > 10){
cout << "Throw of " << throwOne << " is invalid because you can't roll more than 10 on one throw" << endl;
}if (throwTwo > 10){
cout << "Throw of " << throwTwo << " is invalid because you can't roll more than 10 on one throw" << endl;
}if (throwThree > 10){
cout << "Throw of " << throwThree << " is invalid because you can't roll more than 10 on one throw" << endl;}
return;
}
When I run it, it doesn't matter what I enter be it 1 or 100 it says:
"Throw of 2293504 is invalid because you can't roll more than 10 on one throw"
"Throw of 2293512 is invalid because you can't roll more than 10 on one throw"
"Throw of 2293700 is invalid because you can't roll more than 10 on one throw"
It should print what number I type in only if I type a number more than 10... I'm stuck... can someone help please!?
Your functions do not modify the values you pass to them like you seem to think they do. And the throw variables FindErrors() are completely separate from the ones you've declared elsewhere.
#include <iostream>
usingnamespace std;
void FirstThrow(int throwOne); //see note 1
void SecondThrow(int throwTwo); //see note 1
void ThirdThrow(int throwThree); //see note 1
void FindErrors();
int main ()
{
int throwOne, throwTwo, throwThree;
FirstThrow(throwOne);
SecondThrow(throwTwo);
ThirdThrow(throwThree);
FindErrors();
return 0;
}
void FirstThrow(int throwOne) //see note 1
{
cout << "Enter the first score: ";
cin >> throwOne;
return; //this is not required
}
void SecondThrow(int throwTwo) //see note 1
{
cout << "Enter your second score: ";
cin >> throwTwo;
return; //again useless
}
void ThirdThrow(int throwThree) //see note 1
{
cout << "Enter your third score: ";
cin >> throwThree;
return; //useless
}
void FindErrors()
{
int throwOne, throwTwo, throwThree; //see note 2
if (throwOne > 10)
{
cout << "Throw of " << throwOne << " is invalid because you can't roll more than 10 on one throw" << endl;
}
if (throwTwo > 10)
{
cout << "Throw of " << throwTwo << " is invalid because you can't roll more than 10 on one throw" << endl;
}
if (throwThree > 10)
{
cout << "Throw of " << throwThree << " is invalid because you can't roll more than 10 on one throw" << endl;
}
return; //still useless
}
Note 1: From the way you are using these variables, I am guessing you meant to pass by reference. The way you currently have it, you are using pass by value.
Note 2: These variables are not the same ones from main; instead they are uninitialized values. You should pass the ones from main to your errors function (you may use pass by value here).
EDIT: Zhuge had a huge head start and beat me in the Z order.