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; } }

4th Mar 2017, 6:03 AM
Aayush Pradhan
Aayush Pradhan - avatar
13 ответов
+ 8
1. Put << before all endl e.g: cout<<"hello world "<<endl; 2.You didn't asked for the value 'a'
4th Mar 2017, 6:18 AM
Mr.Robot
Mr.Robot - avatar
+ 8
NP mate , keep coding :)
4th Mar 2017, 6:20 AM
Mr.Robot
Mr.Robot - avatar
+ 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.
4th Mar 2017, 6:48 AM
Mr.Robot
Mr.Robot - avatar
+ 7
Do not terminate main() , remove the semicolon in main() function.
4th Mar 2017, 6:29 AM
Mr.Robot
Mr.Robot - avatar
+ 7
I'll post my version of your code , wait.
4th Mar 2017, 6:34 AM
Mr.Robot
Mr.Robot - avatar
+ 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; } }
4th Mar 2017, 6:27 AM
Aayush Pradhan
Aayush Pradhan - avatar
+ 1
Oh, all right, thank you so much 🙏🙏biiii, have a good day☺️
4th Mar 2017, 6:49 AM
Aayush Pradhan
Aayush Pradhan - avatar
+ 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()
4th Mar 2017, 11:08 AM
Peter Festejo
Peter Festejo - avatar
0
Ok, i'll try that, THANK YOU SO MUCH😊
4th Mar 2017, 6:19 AM
Aayush Pradhan
Aayush Pradhan - avatar
0
It's saying,playground\4:1 expected unqualified-id before '{' token
4th Mar 2017, 6:30 AM
Aayush Pradhan
Aayush Pradhan - avatar
0
Ok thank you
4th Mar 2017, 6:35 AM
Aayush Pradhan
Aayush Pradhan - avatar
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
4th Mar 2017, 6:45 AM
Aayush Pradhan
Aayush Pradhan - avatar
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. <<
8th Mar 2017, 2:49 PM
firas