Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,933 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,725 people online right now. Registration is fast and FREE... Join Now!




FLAMES & HOPE

 
Reply to this topicStart new topic

FLAMES & HOPE

emotakoh
4 Jan, 2008 - 07:56 PM
Post #1

New D.I.C Head
*

Joined: 1 Oct, 2007
Posts: 4


My Contributions
HELP SOS! ! !
I need to output a c program that will accept two strings that will play FLAMES and HOPE that has an acronym of (Friends,Lovers,Anger,Marriage,Enemies,Sweethearts) and
(Hindi,Oo,Puwede,Ewan)

I tried it many times before but I failed
Here is my codes:

CODE

/*FLAMES*/
#include<stdio.h>
#include<string.h>
main()
{
    char str1[20];
    char str2[20];
    int k,l,m;
    clrscr();
        printf("Enter a name: \n");
            gets(str1);
        printf("Enter another name: \n");
            gets(str2);
    {
    if(!strcmp(str1==str2))
        strlen+=%6
            switch(m){
                case 0:printf("Friends");break;
                case 1:printf("Lovers");break;
                case 2:printf("Anger");break;
                case 3:printf("Marriage");break;
                case 4:printf("Enemies");break;
                case 5:printf("Sweethearts");break;
                }
    }
getch();
}


CODE

/* HOPE */
#include<stdio.h>
#include<string.h>
main()
{

    char str1[20];
    char str2[20];
    int str,k,l,m;
    clrscr();
        printf("Enter a name: \n");
            gets(str1);
        printf("Enter another name: \n");
            gets(str2);
    {


    if(strcmp(str[1]==str[2]))
        strlen+=%4
            switch(m){
                case 0:printf("Hindi");break;
                case 1:printf("Oo");break;
                case 2:printf("Puwede");break;
                case 3:printf("Ewan");break;
                }


    }
getch();
}


*edit: Please use code tags next time. Thanks!



This post has been edited by Martyr2: 5 Jan, 2008 - 02:32 PM
User is offlineProfile CardPM
+Quote Post

Tom9729
RE: FLAMES & HOPE
4 Jan, 2008 - 09:08 PM
Post #2

Debian guru
Group Icon

Joined: 30 Dec, 2007
Posts: 1,589



Thanked: 12 times
Dream Kudos: 325
My Contributions
You might start by putting your code inside code tags. smile.gif Like this code.gif

* You're missing semicolons in a few places, and in others you're referring to variables that don't exist.

* Also, the proper usage of strcmp is strcmp(char* str1, char* str2), and it returns 0 if the strings match so you're going to want to add a "!" before it ("not") in that final if-statement.

* strlen is a function, not a variable.

* You're using a switch statement on a variable that's always going to be zero (m).

* Your main method should be of the type int, and should return an int (EXIT_SUCCESS, or 0).
CODE

int main()
{
    // Stuff.

    return EXIT_SUCCESS;
}


* Also, I couldn't tell, are you trying to compile that as two programs or one? Because you can only have one main.

This post has been edited by Tom9729: 5 Jan, 2008 - 01:38 PM
User is online!Profile CardPM
+Quote Post

DPR
RE: FLAMES & HOPE
5 Jan, 2008 - 01:32 PM
Post #3

New D.I.C Head
*

Joined: 20 Dec, 2006
Posts: 17


My Contributions
I'm confused as to what you're trying to achieve huh.gif
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: FLAMES & HOPE
5 Jan, 2008 - 02:51 PM
Post #4

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
I am going to show you a working version of what your game might be like. I am not familiar with the game but it sounds like a game we use to play in school where you made a little toy out of paper, wrote colors, numbers etc on the pieces and a person would make choices to tell their fortune.

In the game below I have made a few modifications that you might want to take and use in the HOPE game. I first collect the names, add their lengths together and divide (modulus) the sum by 6 to get one of the fortunes in the switch statement.

So basically you enter "Tom" and "Brandy" and get "Marriage". Which comes out to Tom (3) + Brandy (6) = 9 % 6 = 3, number 3 is "marriage".

You can use any formula you want to get the value of "m". I put in an example for you.

CODE

/*FLAMES*/
#include<stdio.h>
#include<string.h>

// Needed for getch()
#include <conio.h>

int main()
{
    char str1[20];
    char str2[20];
    int m;

    // Collect first name
    printf("Enter a name: \n");
    gets(str1);

    // Collect second name
    printf("Enter another name: \n");
    gets(str2);

    // Compare to see if they are not equal
    if(strcmp(str1,str2) != 0) {
        // Here is one method you could use... add length of two names
        // mod it with 6 to determine their relationship
        // Store it into "m" (notice the casting to int and semicolon on the end)
        m = (int)(strlen(str1) + strlen(str2)) % 6;

        // Use "m" to print their relation
        switch(m){
            case 0:printf("Friends");break;
            case 1:printf("Lovers");break;
            case 2:printf("Anger");break;
            case 3:printf("Marriage");break;
            case 4:printf("Enemies");break;
            case 5:printf("Sweethearts");break;
        }
    }
    getch();
}


Read through the in code comments and you will see what I am doing. It is pretty straight forward. Hope this is what you were after.

Enjoy!

"At DIC we be making matches on a daily basis, we are match making code ninjas!" wub.gif decap.gif
User is offlineProfile CardPM
+Quote Post

lex_12
RE: FLAMES & HOPE
7 May, 2008 - 06:49 PM
Post #5

New D.I.C Head
*

Joined: 7 May, 2008
Posts: 5

Is there a string function where you can count the number of the same letters on the 1st and 2nd input?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 03:26PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month