Beginner NEEDS help

Write a C program that show the following menu items and gets the user input that is one of letters given in brackets. Then, it calls the corresponding user-defined function. For example, if the user hits V key from the keyboard, program calls the fViewMenu() function. It is expected that you should write these functions as well :).
[F]ile -> fFileMenu()
[E]dit -> fEditMenu()
[V]iew -> fViewMenu()
[O]ptions -> fOptionsMenu()
[H]elp -> fHelpMenu()
Last edited on
closed account (10oTURfi)
http://www.cplusplus.com/forum/beginner/1/

:)
im at university. i dont know much things about programming. its 3rd lesson and he asked me this question. i asked if you help. Thx.

Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.

its okay. but c'mon. its just 3rd lesson...
Last edited on
closed account (10oTURfi)
I'll give you hint.

use switch(input) where input is char. and then for example in
case 'F ':
call fFileMenu();
Last edited on
That's not much of a hint.....the professor already told him that! lol...
i know only if-else printf integer's and variable's
now im looking for siwtch command. thx. if it helps.
Okay, based on your (apparent) lack of C++ knowledge (or the difference between C and C++), I would recommend that you spend the next four to five hours reading everything in http://www.cplusplus.com/doc/tutorial/
is it right? im trying something
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
#include <conio.h>
int main(void)
{
char folder, c;
printf("Select folders and write its first character. Folders: File, Edit, View, Options, Help");
scanf("%d" &folder);
switch (folder) {
       case 'F':
       case 'f':printf(you are in file folder\n);break;
       }
       c=getch();
       return 0;
       }

Last edited on
If you want C++, you're barking up the wrong tree.
rofl. just begining -.- i know some matlab. But C is really hard. it gives an error at
scanf("%d" &folder);
Last edited on
That's because &folder doesn't exist - it hasn't been initialized.
what should i do?
Last edited on
Initialize it.
ciphermagi you are really helpfull -.-'
I told you what you need to do with your level of understanding, and you decided not to take my advice. So I'm answering your specific questions with specific answers.

What I'm not doing, and won't do, is what you haven't specifically asked me to do, but apparently is what you're seeking: write your program for you.
#include <stdio.h>
#include <conio.h>
main(void)
{
char folder, c;
printf("Select folders and write its first character. Folders: File, Edit, View, Options, Help");
scanf("%d", &folder);
switch (folder) {
case 'f':
case 'F':printf("You are in file folder\n");break;
}
c=getch();
return 0;
}
(You r right ciphermagi sry. i have to be quickly . i couldnt go last lesson. Im tryng to do it since 3hour. its really hard to learn myself. thx for helping )
i wrote it. and it worked. but when i pressed F and enter it closes. whats wrong ?
Last edited on
You sure %d doesn't look for an int?
i was making wrong program. rofl this is working. really working . OMG . Crap. this C is cool .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <conio.h>
int fFileMenu(){
    printf("This is file menu");
}
int fEditMenu(){
    printf("This is edit menu");
}
int fViewMenu(){
    printf("This is view menu");
}
int fOptionsMenu(){
    printf("This is options menu");
}
int fHelpMenu(){
    printf("This is help menu");
}



int main(void)
{
char myAnswer, c;
printf("[F]ile [E]dit [V]iew [O]ptions [H]elp \n"); scanf("%c", &myAnswer);
switch (myAnswer) {
case 'f':
case 'F': fFileMenu(); break;
case 'e':
case 'E': fEditMenu(); break;
case 'v':
case 'V': fViewMenu(); break;
case 'o':
case 'O': fOptionsMenu(); break;
case 'h':
case 'H': fHelpMenu(); break;
default: printf("I think your answer is Maybe ?\n");
}
c = getch();
return 0;
}
Let me give you a tip for when you get to more programming. This will help you and others read your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
int main(void)
{
    char myAnswer, c; // Indent
    printf("[F]ile [E]dit [V]iew [O]ptions [H]elp \n"); // Indent
    scanf("%c", &myAnswer); // New line after every command
    switch (myAnswer) { // Indent
        case 'f': // Indent
        case 'F': // Indent
            fFileMenu(); // New line after every command
            break; // New line after every command
        case 'e': // Indent
        case 'E': // Indent
            fEditMenu(); // New line after every command
            break; // New line after every command
        case 'v': // Indent
        case 'V': // Indent
            fViewMenu(); // New line after every command
            break; // New line after every command
        case 'o': // Indent
        case 'O': // Indent
            fOptionsMenu(); // New line after every command
            break; // New line after every command
        case 'h': // Indent
        case 'H': // Indent
            fHelpMenu(); // New line after every command
            break; // New line after every command
        default: // Indent
            printf("I think your answer is Maybe ?\n"); // New line after every command
    } // Indent
    c = getch(); // Indent
    return 0; // Indent
}


Repetition makes memories stick.
Last edited on
ty. so much. for everything
hmmm // same in matlab %
so its for comments .
Last edited on
Topic archived. No new replies allowed.