Trying to make program for my daughter

Hi guys, brand new to the forum, and programming in general.
I just started learning how to use c++ this week, and wanted to make a console application to help my 5 year old with her sight words. basically what i wanted was to have output "Enter a sight word:" then have a list of her sight words to where she could enter any of them and either tell her YAY! or Try again. I'm too new at this to figure it out on my own, so I'm asking for some assistance on what i need to do. Any help would be greatly appreciated! Thanks
I don't know what a "sight word" is, but I think you're asking for a program that shows a list of words, and then accepts input, and if the input matches one of the words, the output is YAY!, and if the input does not match, the output is "Try Again". Is that what you're asking?
right, thats what im looking to do, except i dont want her to see the list of words, she needs to spell them out. does that make sense?
btw, she has 10 sight words to date. she gets 5 new words every week, so i will need to be able to add them to the list.
Last edited on
You could add the words to a container, ask the user for an input, run a for loop, if the input matches any of the words in the container, output "YAY", if not, output "Try again!".
ok, makes sense. now as far as variables and declarations go, which ones would i use? Thanks guys!
Do you know how to use arrays, vectors or any other kind of containers ?
not quite there yet. i could research it, though. just needed a push in the right direction.
This should actually be fairly easy, with arrays I think. I work in the educational industry occasionally so I might actually put together a similar project. be back soon with a first round of it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <vector>
#include <string>

int main()
{
    std::vector<std::string> wordList;
	
    wordList.push_back("to"); // word 1
    wordList.push_back("he"); // word 2
    // continue adding words...

    std::cout << "Enter a sight word: " << std::endl;
    std::string word;
    std::cin >> word;

}


Then, you can run a for loop and compare word against the list of words in vector wordList.
Last edited on
That would be great! I appreciate the help guys! should I study arrays a little bit to get started?
Thanks Dash! will try that out!
just wondering, is there a way to ignore the first letter case? for example to make this available to an older group who would possibly think they should capitalize the first letter but you don't want to have to duplicate each word throughout the program.
Yes, you can use tolower function in cctype header file.
Here's something to get you started. You can add in a menu to chose categories or even make it point based like a game. Could even remove words as they are found so the list to chose from get's smaller

word_list.txt
1
2
3
4
5
words
list
hello
that
where


Program:
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include<string>
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>

using namespace std;

void main() {

    string word;
    vector<string> words;

    //build word list
    ifstream wordList("word_list.txt");
    if(wordList.is_open())
    {
        while(wordList.good())
        {
            getline(wordList, word);
            //make sure all words are lowercase
            transform(word.begin(), word.end(), word.begin(), tolower);
            words.push_back(word);
        }
        wordList.close();
    }

    while(!words.empty()){

        //get input
        cout << "Enter Word: ";
        cin >> word;

        //check for early out
        if(word == "-1")
            break;

        //convert input to all lowercase
        transform(word.begin(), word.end(), word.begin(), tolower);

        //find word in list
        bool found = false;
        for(int i = 0; i < words.size(); i++)
        {
            if(words[i] == word)
            {
                found = true;
                break;
            }
        }

        if(found)
            cout << "Yay!" << endl;
        else
            cout << "Try again." << endl;

        cout << endl;

    }

    cout << "closing..." << endl;

    system("pause");
}


Output:

Enter Word: going
Try again.

Enter Word: hello
Yay!

Enter Word: -1
closing...

Press any key to continue . . .


Look at:
file input/output
http://www.cplusplus.com/doc/tutorial/files/

vectors
http://www.cplusplus.com/reference/stl/vector/

strings
http://www.cplusplus.com/reference/string/
Anthony, i copied pasted this and all i got was closing press any key to continue. Maybe i did the word_file.txt wrong?
Also, is there a way to add audio to the code ie output Yay! has a ta-da trumpet sound and Try again does a womp womp wooooommmm? once again, total noob to this and it may be above my pay grade at the moment...
C++ does not have built-in support for sound. You have to use an external library.

Edit: Most likely your program couldn't open the file.
Last edited on
Sorry I should have put in a notification of a file not being opened. If you're running the executable then you put the file in the same folder. If you're running the program through an IDE then you need to put it somewhere the debugger is looking. For Visual Studios 2010 it goes in the project folder- One up from the debug folder.

@Dash

Sound is supported through the windows libraries.

If you want a sound file to be played do this:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <windows.h>
#include <MMSystem.h>

#pragma comment(lib, "winmm.lib")

int main(){

    //plays sound and continues execution without waiting for sound to stop
    PlaySound(TEXT("file_name.wav"), NULL, SND_ASYNC);

    //plays sound file on loop. "background music"
    PlaySound(TEXT("file_name.wav"), NULL, SND_ASYNC | SND_LOOP);

    //Stops music that is currently playing
    PlaySound(NULL, 0, 0);

    return 0;
}


I think it might have to be .wav for it to work. Wouldn't hurt to try .mp3

EDIT:
Sound files go in the same file directory as your text file. For testing purposes make your paths to these files like this:"c:\\Sound_file.wav"

That way you know exactly where they are on the hard drive until you figure out where to put them for your local executable

References:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx

http://www4.carthage.edu/faculty/ewheeler/programming/CPP/Console%20Sound%20and%20Color/Console%20Sound%20and%20Color.htm
Last edited on
Awesome!! thanks Anthony, you are the man! it's working and functional, so thanks again! i dont know if there's a rep system here so +1!
You're welcome! If you study the code and resources I linked you can expand really expand on this and make it into something awesome.
Will do. Last night i was watching videos on youtube, made by krashcourse, and they really helped me understand more of the language than anything i have read so far. Im going to study the code, and check out the resources you've provided, and hopefully one day i could do something like this for someone else.
Topic archived. No new replies allowed.