0
Please tell me what's the error and how to correct it.
#include <iostream> using namespace std; int main(); { int a;string s; cout << "hello,how may i help you?" endl; cin>>s; if (s=="i want to borrow some money") { cout <<"how much?" endl; if (a>0&&a<=1000) { cout<<"All right friend" endl; } if (a>1000&&a<=5000) { cout<<"that's a little much but it's OK as you are my friend" endl; } else { cout<<"pagal hai kya?? Itne paise kaun dega mujhe,Golu mama??" endl; } } else { cout<<"SORRY,I'M REALLY SORRRRYYYY" endl; } }
13 odpowiedzi
+ 8
1. Put << before all endl
e.g: cout<<"hello world "<<endl;
2.You didn't asked for the value 'a'
+ 8
NP mate , keep coding :)
+ 8
#include <iostream>
using namespace std;
int main() {
int amount;
string str;
cout<<"Hello , How may i help you? "<<endl;
cout<<"Do you want to Borrow some money? Y/N"<<endl;
cin>>str;
if(str=='Y')
{
cout<<"How much do you want?"<<endl;
cin>>amount;
if(amount > 0 && amount <= 1000 )
cout<<"Take it my friend "<<endl;
else if(amount > 1000 && amount <= 5000)
cout<<"Grrrr, Its little much but as your my friend take It"<<endl;
else
cout<<"<redacted> , Get lost"<<endl;
}
else
cout<<"sorry my friend";
return 0;
}
Run this in your PC compiler not in code playground.
Re:
No profanity please.
+ 7
Do not terminate main() , remove the semicolon in main() function.
+ 7
I'll post my version of your code , wait.
+ 1
#include <iostream>
using namespace std;
int main();
{
int a;string s;
cout << "hello,how may i help you?"<<endl;
cin>>s;
cin>>a;
if (s=="i want to borrow some money")
{
cout <<"how much?" endl;
if (a>0&&a<=1000)
{
cout<<"All right friend"<<endl;
}
if (a>1000&&a<=5000)
{
cout<<"that's a little much but it's OK as you are my friend"<<endl;
}
else
{
cout<<"pagal hai kya?? Itne paise kaun dega,Golu mama?"<<endl;
}
}
else
{
cout<<"SORRY,I'M REALLY SORRRRYYYY"<<endl;
}
}
+ 1
Oh, all right, thank you so much 🙏🙏biiii, have a good day☺️
+ 1
Replace [cin >> s;]
To
cin.getline(s);
It gets white spaces like "i want" if you use cin it only gets "i";
Also
After the cout << "how much"
Put cin >> amount;
Like mr. robot say put "<<" on before endl and remove semi colon on main()
0
Ok, i'll try that, THANK YOU SO MUCH😊
0
It's saying,playground\4:1 expected unqualified-id before '{' token
0
Ok thank you
0
#include <iostream>
using namespace std;
int main()
{
int a;string s;
cout << "hello,how may i help you?"<<endl;
cin>>s;
cin>>a;
if (s=="i want to borrow some money")
{
cout <<"how much"<<endl;
if (a>0&&a<=1000)
{
cout<<"All right friend"<<endl;
}
if (a>1000&&a<=5000)
{
cout<<"that's a little much but it's OK as you are my friend"<<endl;
}
else
{
cout<<"pagal hai kya?? Itne paise kaun dega,Golu mama?"<<endl;
}
}
else
{
cout<<"SORRY,I'M REALLY SORRRRYYYY"<<endl;
}
}
Now it has no syntax error but has logical error, it's not working as expected plz try to run it yourself and check it and improve it
0
U must write
Include<string>
And the print staitment is wrong
Cout<<"bla bla bla bla"<<endl;
Or
Cout<<"bla bla bla bla";
U can't write endl; Without. <<