how call functions in c++

Write your question here.
Hi
I have program have many functions I want if the first functions valid call the second function if the second function valid call the thierd
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
  // first 
bool ValidateInput(string cardNumber)
{
	bool correct;
	if ((cardNumber.length() >= 13 && cardNumber.length() <= 16 && cardNumber > "9" || cardNumber < "0"))
	{
		cout << "Your Card Number is Valid" << cardNumber << endl;
	}
	else
		{
			cout << "Your Input Invlid try again" << endl;
		}


}
//second 
bool IsValid(string cardNumber)
{
	bool correct;
	return ((SumOfDoubleEvenPlace(cardNumber) + SumOfOddPlace(cardNumber)) % 10 == 0);
}
//third 
bool StartsWith(string cardNumber, string substr)
{
	return (cardNumber.compare(0, 1, "4") == 0) || // TYPE VISA.
		(cardNumber.compare(0, 1, "5") == 0) || // TYPE MASTER.
		(cardNumber.compare(0, 2, "37") == 0) || // TYPE AMERICAN EXPRESS
		(cardNumber.compare(0, 1, "6") == 0); // TYPE DISCOVER.   
}
1
2
3
4
5
6
7
8
9
string cardNumber = "123abc»§Ð°¿ıº";
if (ValidateInput(cardNumber))
{
	if (IsValid(cardNumber))
	{
		bool startsWith123 = StartsWith(cardNumber, "123");
		...
	}
}


Don't forget to return a value from ValidateInput.
Here is another simple program to demonstrate what youre saying so hopefully it will make it easier to understand. It shows you how to function calls the next function and so on and so forth but also how the program returns through those same functions back to main.

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
#include <iostream>
#include <string>

void thirdFunc()
{
    std::cout << "This is the third and final function." << std::endl;
    std::cout << "Leaving Third Function." << std::endl;  
    return; 
}

void secondFunc()
{
    std::cout << "This is the second function." << std::endl;
    std::cout << "Calling third function." << std::endl;
    thirdFunc();
    std::cout << "Back in the second function." << std::endl;
    return;
}

void firstFunc()
{
    std::cout << "This is the first function." << std::endl;
    std::cout << "Calling Second function now." << std::endl;
    secondFunc();
    std::cout << "Back in the first function." << std::endl;
    return;
}

int main()
{
  firstFunc(); 
  std::cout << "Inside Main" << std::endl;
}
Topic archived. No new replies allowed.