Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ using studio visual 2010 to complile. Please be specific with Syntax languag

ID: 3558580 • Letter: C

Question

C++ using studio visual 2010 to complile. Please be specific with Syntax language.

First your program should ask if the credit card is MasterCard or visa card. Then ask the 16 digit credit card number. Then add all the digits in the credit card number and get the modulo 10. If the modulo 10 of the summation of all the digits is zero, then its valid visa card. If the modulo 10 of the summation of all the digits is 1 then its valid MasterCard. Otherwise, the number customer has entered is an invalid card number.

For example, say the card number is 1234 5678 6789 1235 and its visa card. To validate it, first add all the digits

1+2+3+4+ 5+6+7+8+ 6+7+8+9 +1+2+3+5 = 77 then get mod 10 of 77   (77%10 = 7) Since it

Explanation / Answer

#include<iostream>
using namespace std;
#include<string.h>
#include<stdlib.h>
int main()
{
   int choice; char card[17];
   cout<<"Enter 1 for Visa and 2 for MasterCard :";
   cin>>choice;
   cout<<"Enter the 16 digit card no.";
   cin>>card;
   if(strlen(card)!=16 )
   {
       cout<<"Enter valid card no.";
       return 1;
   }
   int i=0,sum=0;
   while( i<16 )
           {sum+=(card[i]-'0');i++;}
   if(i == 16)
   {
       if(choice==1&&sum%10==0)cout<<"Valid Visa Card";
       else if(choice==2&&sum%10==1)cout<<"Valid Master Card";
       else
           cout<<"Invalid Card";
   }
   else
   cout<<"Invalid Card Number";
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote