My goal with this program is to get input for four values.
(A, B , C , D) and just rotate them so that:
A ----> B
B ----> C
C-----> D
D-----> A
However in my program, all my code appears correct to me, And yet it keeps messing up the roation of the variables.
Code:
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
void screenHeader();
void getInput(int &a, int &b, int &c, int &d);
void sendInput(int &a, int &b, int &c, int &d);
void doRotation(int &a, int &b, int &c, int &d);
void finalOutput(int a, int b,int c,int d);
int main()
{
int a, b, c, d;
system("clear");
screenHeader();
getInput(a, b, c, d);
doRotation(a, b, c, d);
finalOutput(a, b, c, d);
return 0;
}
void screenHeader()
{
cout << "------------------------------------------------------------" << endl;
cout << "------------------------------------------------------------" << endl;
cout << "--------------------Rotation Program------------------------" << endl;
cout << "------------------------------------------------------------" << endl;
cout << " The purpose of this program is to let the user(you)input" << endl;
cout << " four values for the variables (A, B, C, D) when you input" << endl;
cout << " the numerical value for each of these letters the program" << endl;
cout << " will then proceed to rotate the values and assign them to" << endl;
cout << " the following variable. " << endl;
cout << "-----------------------Example------------------------------" << endl;
cout << " A -----> B " << endl;
cout << " B -----> C " << endl;
cout << " C -----> D " << endl;
cout << " D -----> A " << endl;
cout << "------------------------------------------------------------" << endl;
cout << "------------------------------------------------------------" << endl;
cout << "------------------------------------------------------------" << endl;
}
void getInput(int &a, int &b, int &c, int &d)
{
cout << "Please enter your input for the A variable."<< endl;
cin >> a;
cout << "Please enter your input for the B variable." << endl;
cin >> b;
cout << "Please enter your input for the C variable." << endl;
cin >> c;
cout << "Please enter your input for the D variable " << endl;
cin >> d;
sendInput(a, b, c, d);
}
void sendInput(int &a, int &b, int &c, int &d)
{
cout << "You have entered: " << a << " for theA variable." << endl;
cout << "You have entered: " << b << " for the B variable." << endl;
cout << "You have entered: " << c << " for the C variable." << endl;
cout << "You have entered: " << d << " for the D variable." << endl;
}
void doRotation( int &a, int &b, int &c, int &d)
{
int temp;
temp =a;
a = b ;
temp =b;
b = c ;
temp =c;
c = d ;
temp =d;
d = a ;
}
void finalOutput(int a,int b,int c,int d)
{
cout << "-----------------------------" << endl;
cout << "-----------------------------" << endl;
cout << "Your new value for A is now: " << a << endl;
cout << "Your new value for B is now: " << b << endl;
cout << "Your new value for C is now: " << c << endl;
cout << "Your new value for D is now: " << d << endl;
cout << "----------------------------" << endl;
cout << "----------------------------" << endl;
}
My output keeps giving me this:
Code:
------------------------------------------------------------
------------------------------------------------------------
--------------------Rotation Program------------------------
------------------------------------------------------------
The purpose of this program is to let the user(you)input
four values for the variables (A, B, C, D) when you input
the numerical value for each of these letters the program
will then proceed to rotate the values and assign them to
the following variable.
-----------------------Example------------------------------
A -----> B
B -----> C
C -----> D
D -----> A
------------------------------------------------------------
------------------------------------------------------------
------------------------------------------------------------
Please enter your input for the A variable.
1
Please enter your input for the B variable.
2
Please enter your input for the C variable.
3
Please enter your input for the D variable
4
You have entered: 1 for the A variable.
You have entered: 2 for the B variable.
You have entered: 3 for the C variable.
You have entered: 4 for the D variable.
-----------------------------
-----------------------------
Your new value for A is now: 2
Your new value for B is now: 2
Your new value for C is now: 3
Your new value for D is now: 4
----------------------------
----------------------------
Any suggestions on what could be messing this up would be greatly appreciated. Thanks.