problem with swapping values in array
Mar 9, 2014 at 6:00pm UTC
hey guys am trying to swap numbers within my array but i keep getting the same number from text file not been swapped.....please help....ignore my print function.....thanx in advance
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
#include <iostream>
#include <vector>
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
void getvaluesfromfile(vector<int >&NUMBER)
{
int number=0;
ifstream infile("indata.txt" );
while (infile>>number)
{
NUMBER.push_back(number);
}
}
/*void print(vector<int>&NUMBER)
{
int decoy;
decoy=NUMBER[0];
int n1,n2,n3,n4;
n1=decoy%10;
n2=(decoy/10)%10;
n3=(decoy/100)%10;
n4=(decoy/1000)%10;
NUMBER.push_back(n4);
NUMBER.push_back(n3);
NUMBER.push_back(n2);
NUMBER.push_back(n1);
//cout<<NUMBER[0];
}*/
void swapfunction(vector<int >&NUMBER)
{
int decoy;
decoy=NUMBER[0];
int n1,n2,n3,n4;
n1=decoy%10;
n2=(decoy/10)%10;
n3=(decoy/100)%10;
n4=(decoy/1000)%10;
NUMBER.push_back(n4);
NUMBER.push_back(n3);
NUMBER.push_back(n2);
NUMBER.push_back(n1);
const int SIZE=4;
int digit[SIZE]={n4,n3,n2,n1};
swap(digit[0],digit[2]);
cout<<NUMBER[0];
}
int main()
{
vector<int > NUMBER;
getvaluesfromfile(NUMBER);
//print(NUMBER);
swapfunction(NUMBER);
}
Topic archived. No new replies allowed.