我已經用C++編寫了一個用於添加盧比和paisa的程序。 我的頭文件如下:在C++中添加盧比和paise
#ifndef CURRENTY_H
#define CURRENT_H
class current
{
long Rs;
int paise;
public:
current()
{
Rs=0;
paise=0;
}
void get();
void operator+=(current &t);
void put();
};
和我current.cpp文件
#include<iostream>
#include"current.h"
void current::get()
{
std::cout<<"\nEnter currency in Rs:";
std::cin>>Rs;
std::cout<<"\nEnter currency in Paise:";
std::cin>>paise;
}
void current::operator+=(current &t)
{
Rs+=t.Rs;
paise+=t.paise;
std::cout<<"\n\nThe added currncy Rs: "<<Rs<<"."<<paise;
}
void current:: put()
{
std::cout<<Rs<<""<<paise;
}
和我的main.cpp是
#include <QCoreApplication>
#include "current.h"
#include<iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
current c1,c2;
c1.get();
c2.get();
std::cout<<"\n\tFirst currency Rs:";
c1.put();
std::cout<<"\n\tSecond currncy Rs:";
c2.put();
c1+=c2;
return a.exec();
}
和輸出我得到的是
Enter currency in rs: 40
Enter currency in paisa : 90
Enter currency in rs : 50
Enter currency in paisa: 90
first currency is : 40.90
second currency is 50.90
Added currency is : 90.180
現在問題是什麼我我面臨的是我想在輸出轉換,即增加貨幣是:90.180。轉換任何數字都在100以上(派薩),將其轉換成盧比
Expected output shoud be :Added currency is : 91.8
如何達致這?
這是否創建了任何其他問題,因爲答案不被接受?它爲我工作。 – Swapnil
'operator + =()'應該帶一個'const'引用。 – IInspectable