I want you to correct something or add something in the code to get the output that is required in the instructions. And just to remind you the code is incomplete. here is my code.
I want you to correct something or add something in the code to get the output that is required in the instructions. And just to remind you the code is incomplete. here is my code.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Topic Video
Question
instructions
program Credit Card Validator - Takes in a credit card number from a common credit card vendor (Visa, MasterCard, American Express, Discover) and validates it to make sure that it is a valid number (look into how credit cards use a checksum)
//what I need
As you can see from the instruction, I have incomplete code and I want you to correct something or add something in the code to get the output that is required in the instructions. And just to remind you the code is incomplete. here is my code.
#include <iostream>
#include<string>
#include<fstream>
using namespace std;
void printCN(string cardCN,int size);
int main()
{
string cardInput = "";
constint size = 16; // Number of digits the card number have
int card[size]; //This array stores card number
int sum = 0;
int oddSum = 0, evenSum;
cout << "Enter Credit Card Number: ";
cin >> cardInput;
for (int counter = 0; counter < cardInput.size(); counter++) card[counter] = cardInput[counter]- '0';
//Luhn Alogrithm
for (int counter = size - 1; counter >=0; counter--)
{
int placeholder;
int x = card[counter];
if (counter % 2 ==0)
{
placeholder = x * 2;
if (placeholder > 9) placeholder = placeholder - 9;
evenSum += placeholder;
}
else
{
placeholder = x;
oddSum += placeholder;
}
}
sum = evenSum + oddSum;
cout << "Even sum is : " << evenSum;
cout << " \n Odd sum is : " << oddSum;
cout << "\n Total sum is : " << sum << "\n\n";
if (sum % 10 == 0) {
cout << "Your";
printCN(cardInput, size);
cout << "card is valid";
}
else {
cout << "Your";
printCN(cardInput, size);
cout << "card is invalid";
}
//4000000000002829
//4000001234567899
return EXIT_SUCCESS;
}
void printCN(string cardInput, int size)
{
if (cardInput[0]=='4')
{
cout << " Visa ";
}
elseif (cardInput[0] == '6')
{
cout << " Master ";
}
else
{
cout << " Unknown Brand ";
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education