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.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 28PE
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
![](/static/compass_v2/shared-icons/check-mark.png)
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
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
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
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![Systems Architecture](https://www.bartleby.com/isbn_cover_images/9781305080195/9781305080195_smallCoverImage.gif)
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning