1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
using namespace std;
int number1(char,int); //My first function
int number2(char,int);//My second function
int result(int,int);//My Third function
int num1,num2,;//Integer variables I will be using
char letter;//The variable that will contain the answer choices.
int main()
{
number1(letter,num1);//This is my first function call
cin.get();
return 0;
}
int number1(char letter, int num1)//This is the function being called and working in action.
{
cout<<"Please enter a number for num1.\n";
cin>> num1;
cin.ignore();
cout<<"You've entered "<< num1 <<" for num1. Is this correct?\n";
cout<<"Type'y' then enter for yes; 'n' then enter for no.\n";
cin>> letter;
cin.ignore();
if (letter == 'y')
{
number2(letter,num2);//This is the continuation of the function calls.
}
else
{
number1(letter,num1);//This is redirecting itself back to the function
} //so the number variable can be edited by the user.
}
int number2(char letter, int num2)//This is my function that has been called by the previous
{ //function.
cout<<"Please enter a number for num2.\n";
cin>> num2;
cin.ignore();
cout<<"You've entered "<< num2 <<" for num2. Is this correct?\n";
cout<<"Type 'y' then enter for yes; 'n' then enter for no.\n";
cin>> letter;
cin.ignore();
if (letter == 'y')
{
cout<<"Calculating results, please wait....\n";
result(num1,num2);//The final and last function.
}
else
{
number2(letter,num2);//Function calling itself to be edited by user.
}
}
int result(int num1, int num2)//Last function comparing to two integers.
{
if (num1 < num2)//I don't know where in the program exactly, but the integer for num1
{ //is somehow lost before here and turned into a zero.
cout<< num1 <<" is less than "<< num2 << ".\n";
}
else if (num1 == num2){
cout<< num1 <<" is equal to "<< num2<<".\n";
}
else
{ cout<< num1 <<" is greater than "<< num2<<".\n";
}
}
|