I was wondering if you could help me with a program question. We have to ask the user to select either a Visa card type or Mastercard type. Then, we must ask the user to enter the 16 digit card number and determine if the card is valid or not using module 10. If the answer is zero then it is a valid Visa card and if the answer is zero the answer is a valid MasterCard. Please help me with the code. I will post what I have. My problem is that the I have not separated the validation for MasterCard separate from visa.
Here is what I have so far:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
string type, num;
int sum = 0, i;
cout << "Please enter the type of card: Visa or MasterCard? "/ <<endl;
cin >> type;
cout << "Please enter the 16 digit card number? ";
cin>>num;
for(i = 0; i < 16; i++)
{
sum += (num[i] - 48);
}
sum %= 10;
if(sum == 0 && num.size() == 16) cout << "Its a valid Visa card.\n";
Sorry, Visa is supposed to be equal to zero and MasterCard is supposed to be 1. My question is what am I missing in my code to not make visa and MasterCard run at the same time? As I have it now, they will both run. I am trying to separate them.
Run at the same time? What do you mean? Do you mean that it would report "valid Visa" if you input "Visa" at the beginning? In that case, you'll need to actually use the "type" variable you read that input into.
I am trying to make the program run the visa check if the user selects visa and MasterCard verification of the user selects mastercard. I just do not want the program checking MasterCard and visa validation at the same time.