Problem having in the output

Problem Statement
Write a program that repeatedly asks the user to enter two money amounts expressed in
old-style British currency: pounds, shillings, and pence. (See Exercises 10 and 12 in
Chapter 2, “C++ Programming Basics.”) The program should then add the two amounts
and display the answer, again in pounds, shillings, and pence. Use a do loop that asks the
user whether the program should be terminated. Typical interaction might be
Enter first amount: £5.10.6
Enter second amount: £3.2.6
Total is £8.13.0
Do you wish to continue (y/n)?
To add the two amounts, you’ll need to carry 1 shilling when the pence value is greater
than 11, and carry 1 pound when there are more than 19 shillings.
Hi Everyone.

i am having a problem with the output of a code . i got a code from a website which shows the correct output .

i changed just the variable names and the output has changed too.

Please tell me why that is happening

CODE FROM THE WEBSITE

#include<iostream>
using namespace std;
void main(void)
{ int m[2][3]; char A,sep; //m (money), sep (char_separator).

do{
cout<<"Enter first amount : \x9c";
cin >>m[0][0]>>sep>>m[0][1]>>sep>>m[0][2];
cout<<"Enter second amount: \x9c";
cin >>m[1][0]>>sep>>m[1][1]>>sep>>m[1][2];
m[0][0] += m[1][0]; m[0][1] += m[1][1]; m[0][2] += m[1][2];
if(m[0][2]>11){m[0][1] += static_cast<int>(m[0][2]/12); m[0][2] %= 12;}
if(m[0][1]>19){m[0][0] += static_cast<int>(m[0][1]/20); m[0][1] %= 20;}
cout<<"Total is : \x9c"<<m[0][0]<<sep<<m[0][1]<<sep<<m[0][2];
cout<<"\n\n !Press c to continue or any key to exit."<<endl<<endl;
}
while(A=='c');
system("pause");
}


CODE WHICH I WROTE AFTER CHANGING VARIABLE NAMES

#include<iostream>
using namespace std;
void main()
{
int pound,shling,panny,pound2,shling2,panny2;
char x,sep;
do
{
cout<<"Enter 1st Amount \x9c";

cin>>pound>>sep>>shling>>sep>>panny;
cout<<"Enter 2nd Amount \x9c";

cin>>pound2>>sep>>shling2>>sep>>panny2;
pound += pound2;
shling += shling2;
panny += panny2;
if(panny>>11)
{
shling+=static_cast<int>(panny/12);
panny %= 12;
}
if(shling>19)
{
shling += static_cast<int>(shling/20);
shling %= 20;
}
cout<<"Total is \x9c"<<pound<<sep<<shling<<sep<<panny<<endl;
cout<<"Enter Y to COntinue";
cin>>x;
}
while(x=='y');
system("pause");
}
This if(panny>>11) should be if(panny>11).

Note that the >> is completely different from >. See Bitwise operators:

http://www.cplusplus.com/doc/tutorial/operators/

I would suggest to use the correct spelling for your names.
Topic archived. No new replies allowed.