What did I do wrong? I feel like crying. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What did I do wrong? I feel like crying.

Each time I use functions, I'm always getting errors I don't understand. The problem is to write a Menu program that a user can select from the list of options. I made it so that if a user enters a number, it says that you entered so and so option. Please don't just correct my code, tell me what I need to learn so that I will know this thing, please. Here is the my code. #include <iostream> #include <string> using namespace std; string list(char easy, char normal, char hard); /*char list(string easy, string mormal, string hard);*/ int main() { string choice = char list(char easy, char normal, char hard); cout << "Your option is: " << choice << endl; return 0; } /*string list(string easy, string normal, string Hard) { cout << Easy }*/ string list(char easy, char normal, char hard) { char easy; { cout << "1. Easy"; cin >> easy; if (easy == 1) } char easy; char normal; { cout << "2. Normal"; cin >> normal; if (normal == 2) } return normal; char hard; { cout << "3. Hard?"; cin >> hard; if (hard == 3) } return hard; }

18th Oct 2019, 8:21 PM
Octopus George
Octopus George - avatar
6 Answers
+ 1
First make it on Solollearn Playground and share code here
18th Oct 2019, 8:27 PM
A͢J
A͢J - avatar
18th Oct 2019, 9:26 PM
Octopus George
Octopus George - avatar
0
I'll start with an advice: do not write a whole program and run it in one step; use many steps, adding one or two lines at every step and running the partial program at the end of every step. The errors are essentially: (1) do not input data many times (inside list() once for easy, once for normal, once for hard): you need only one input! (2) try a better use of brackets: if (...) } does not make any sense (3) remember that for every function there are two different syntaxes: one for declaring it string list(char easy, char normal, char hard) and one for calling it string choice = list(easy, normal, hard) (4) where are the parameters of list() when you call it? You do not need any parameter (5) cout requires always a trailing newline (endl), else nothing is printed Here is your code with corrections: https://code.sololearn.com/ca4m0Je0EeKJ/?ref=app
20th Oct 2019, 5:47 AM
Bilbo Baggins
Bilbo Baggins - avatar
0
Bilbo Baggins is right but cout doesn't always require a trailing new line of any type(endl '\n') and it seem you don't know the syntax of "if" statements and codes after an occured return won't run(or even compile in optimized compilation)
20th Oct 2019, 4:56 PM
AliZ
- 1
I don't know what i'm doing anymore (crying...)
18th Oct 2019, 8:24 PM
Octopus George
Octopus George - avatar
- 1
To write better code you should know debugging. Try to understand error which are coming on Console and solve them one by one.
18th Oct 2019, 9:31 PM
A͢J
A͢J - avatar