What's new

Closed Concatenate problem

Status
Not open for further replies.

joeyer13

Forum Veteran
Elite
Joined
Sep 20, 2016
Posts
1,123
Solutions
7
Reaction
2,576
Points
633
[/CODE]
Code:
May way po ba na ma i add ang string at int para mag loop po yung dalawa na hindi kinoconvert ang isa sa kanila
// eto po yung code
#include <iostream>
#include <sstream>
using namespace std;

string user;
string user1="ryan";
string Ltransaction;
string Maintransaction ;


int AmountToletter;

int main()
{


string choice, transaction;
int pin, deposit, amount , balance, wí†hdráw;


do

{
Ltransaction = "" ;
cout<<"Welcome to Yalung ATM <24 hrs>";
cout<<"\nEnter Username: ";
cin>>user;
cout<<"Enter Pincode: ";
cin>>pin;
if (pin==22 && user==user1)
{
balance=50000;
do
{
do
{

cout<<"\nTRANSACTIONS \nD or d - Deposit \nW or w - wí†hdráw \nB or b - Balance\n";
cout<<"\nEnter Your Transaction: ";
cin>>transaction;
if (transaction=="D" || transaction=="d")
{

do
{
cout<<"Amounts \n1 - 100 \n2 - 200 \n3 - 500 \n4 - 1,000 \n5 - 10,000 \n6 - Others";
cout<<"\nChoose Amount: ";
cin>>choice;
if (choice=="1")
{
amount=100;
}
else if (choice=="2")
{
amount=200;
}
else if (choice=="3")
{
amount=500;
}
else if (choice=="4")
{
amount=1000;
}
else if (choice=="5")
{
amount=10000;
}
else if (choice=="6")
{
cout<<"Enter Amount: ";

cin>>amount;
}
else
{
cout<<"Invalid\n";

amount=0;
}

AmountToletter = amount ;
Ltransaction = "You Deposit:";

do
{
cout<<"Enter Pincode: ";
cin>>pin;
if (pin==22)
{
deposit=balance+amount;
balance=deposit;
cout<<"Deposit Amount: "<<amount<<"\nYour Current Balance is: "<<balance;
}
else if (pin==22 && amount==0)
{
cout<<"Deposit Amount: "<<amount<<"\nYour Current Balance is: "<<balance;
}
else
{
cout<<"\nInvalid Pin!\n";
}
}
while (pin!=22);
cout<<"\nDeposit again? Yes or No?: ";
cin>>choice;
}
while (choice=="Yes");
}
else if (transaction=="W" || transaction=="w")
{
do
{
cout<<"Amounts\n1 - 100\n2 - 200\n3 - 500\n4 - 1,000\n5 - 10,000\n6 - Others";
cout<<"\nChoose Amount: ";
cin>>choice;
if (choice=="1")
{
amount=100;
}

else if (choice=="2")
{
amount=200;
}

else if (choice=="3")
{
amount=500;
}

else if (choice=="4")
{
amount=1000;
}

else if (choice=="5")
{
amount=10000;
}

else if (choice=="6")
{
cout<<"Enter Amount: ";
cin>>amount;

if (amount>balance)
{
cout<<"MACHINE NOW TERMINATING.....\n";
}
}

else
{
cout<<"Invalid\n";
amount=0;
}

do
{
cout<<"Enter Pincode: ";
cin>>pin;

if (pin==22)
{
if (amount<=balance)
{
wí†hdráw=balance-amount;
balance=wí†hdráw;
cout<<"wí†hdráw Amount: "<<amount<<"\nYour Current Balance is: "<<balance;
}
else if (amount>balance)
{
cout<<"wí†hdráw Amount: "<<amount<<"\nYour Current Balance is: "<<balance;
}
else if (amount==0)
{
cout<<"wí†hdráw Amount: "<<amount<<"\nYour Current Balance is: "<<balance;
}
}
else
{
cout<<"\nInvalid Pin!!!!\n";
}
}
while (pin!=22);

cout<<"\nwí†hdráw again? Yes or No?: ";
cin>>choice;
}
while (choice=="Yes");
AmountToletter = amount ;
Ltransaction = "You wí†hdráw:" ;



}
else if (transaction=="B" || transaction=="b")
{
cout<<"Your Balance is: "<<balance<<'\n';
AmountToletter = balance ;
Ltransaction = "You balance:";

}
else
{
cout<<"INVALID TRANSACTION!!\n";
}



stringstream number ;
number << AmountToletter << endl ;
string newString = number.str();

Maintransaction = Maintransaction + Ltransaction + newString ;
}
while (((transaction!="D" && transaction!="d") && (transaction!="W" && transaction!="w")) && (transaction!="B" && transaction!="b"));

cout<<"\nAnother Transaction? Yes or No: ";
cin>>choice;



}
while (choice=="Yes" || choice == "yes");
if (choice == "No" || choice == "no"){
cout << "****** Last transaction*******\n";
cout << Maintransaction ;
cout << "******************************" ;
cout<<"\nTHANK YOU FOR BANKING WITH US!!";
}

}


}
while ((user!=user1 || pin!=22) );



return 0;
}


eto po yung picture
 

Attachments

Last edited:
Tama. Ilagay sa code tag.
Saka sa output mo. Okay naman.
Hindi ko alam anong mali o gustong mangyari ni TS.
 
Yung maintransaction kaso ts nag loloop na siya bilang Maintransaction = Maintransaction +Ltransaction eh kung i plu - plus ko pa si amount as int mag eerror na..
Napag plus ko po yan kasi si amount na convert ko na string ... may ibang way pa po ba para ma add yan na di na coconvert si amount na string ... kasi di daw pwede mag lagay ng ibang libraries kaya ayaw po
Alin ba sa code ang gusto mo mag add? Anong variable?
 
pa try nito paps, baka sakaling pwede
using the library sstream

C++:
#include <iostream>
#include<sstream>
using namespace std;
int main(void){
    stringstream ss;
    ss << 10000;
    string balance = "Balance: " + ss.str();
    cout<<balance;
}
 
C++:
#include <iostream>
using namespace std;

int main()
{
    string str = "Hello I'm ";
    int num = 25;
   
    cout<< str + to_string(num);
    return 0;
}
 
Last edited:
pa try nito paps, baka sakaling pwede
using the library sstream

C++:
#include <iostream>
#include<sstream>
using namespace std;
int main(void){
    stringstream ss;
    ss << 10000;
    string balance = "Balance: " + ss.str();
    cout<<balance;
}
thank you po dito sir yan yung ginawa ko pero bawal daw gumamit ng ubang library haha <iostream> lang daw haha
 
Status
Not open for further replies.

Similar threads

Back
Top