Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 25th, 2005, 11:29 AM   #1
brandcolt
Newbie
 
Join Date: Jan 2005
Posts: 7
Rep Power: 0 brandcolt is on a distinguished road
Whats wrong...

Ok I've made a program...it sucks but it works for what I want it to. Except for one thing. At the very end I have two If statements. If something ='s 1 then it tells you something and if something ='s 2 it tells you something. But for some reason if I type in 1 or 2 both of the statements appear. Any help would be appreciated. Here's the code:


#include <stdio.h>
#include <conio.h>

#include <stdlib.h>

int main(void)

{
char name[10];
char name1[10];
char name2[10];
char name3[10];
char name4[10];
char name5[10];
char name6[10];
char name7[10];
char name8[10];
char name9[10];
char name10[10];
char name11[10];
char name12[10];
char name13[10];
char name14[10];
char name15[10];
char name16[10];
char name17[10];
char name18[10];
char ready[10];
int mark;


printf("\tSTEWART FAMILY GIFT EXCHANGE\n\n");


//Gets all the people's names
printf("Enter the 1st name.\n");
scanf("%s", name);
printf("Oh ok the 1st name is %s\n", name);

printf("\n\nPlease enter the 2nd name.\n");
scanf("%s", name1);
printf("Oh ok the 2nd name is %s\n", name1);

printf("\n\nPlease enter the 3rd name.\n");
scanf("%s", name2);
printf("Oh ok the 3rd name is %s\n", name2);

printf("\n\nPlease enter the 4th name.\n");
scanf("%s", name3);
printf("Oh ok the 4th name is %s\n", name3);

printf("\n\nPlease enter the 5th name.\n");
scanf("%s", name4);
printf("Oh ok the 5th name is %s\n", name4);

printf("\n\nPlease enter the 6th name.\n");
scanf("%s", name5);
printf("Oh ok the 6th name is %s\n", name5);

printf("\n\nPlease enter the 7th name.\n");
scanf("%s", name6);
printf("Oh ok the 7th name is %s\n", name6);

printf("\n\nPlease enter the 8th name.\n");
scanf("%s", name7);
printf("Oh ok the 8th name is %s\n", name7);

printf("\n\nPlease enter the 9th name.\n");
scanf("%s", name8);
printf("Oh ok the 9th name is %s\n", name8);

printf("\n\nPlease enter the 10th name.\n");
scanf("%s", name9);
printf("Oh ok the 10th name is %s\n", name9);

printf("\n\nPlease enter the 11th name.\n");
scanf("%s", name10);
printf("Oh ok the 11th name is %s\n", name10);

printf("\n\nPlease enter the 12th name.\n");
scanf("%s", name11);
printf("Oh ok the 12th name is %s\n", name11);

printf("\n\nPlease enter the 13th name.\n");
scanf("%s", name12);
printf("Oh ok the 13th name is %s\n", name12);

printf("\n\nPlease enter the 14th name.\n");
scanf("%s", name13);
printf("Oh ok the 14th name is %s\n", name13);

printf("\n\nPlease enter the 15th name.\n");
scanf("%s", name14);
printf("Oh ok the 15th name is %s\n", name14);

printf("\n\nPlease enter the 16th name.\n");
scanf("%s", name15);
printf("Oh ok the 16th name is %s\n", name15);

printf("\n\nPlease enter the 17th name.\n");
scanf("%s", name16);
printf("Oh ok the 17th name is %s\n", name16);

printf("\n\nPlease enter the 18th name.\n");
scanf("%s", name17);
printf("Oh ok the 18th name is %s\n", name17);

printf("\n\nOk the names will now be ");
printf("distributed out");
printf("\n\nType ok when ready\n");
scanf("%s", ready);

printf("\n%s gives to %s", name7, name3);
printf("\n%s gives to %s", name1, name9);
printf("\n%s gives to %s", name11, name5);
printf("\n%s gives to %s", name4, name15);
printf("\n%s gives to %s", name2, name17);
printf("\n%s gives to %s", name14, name12);
printf("\n%s gives to %s", name6, name13);
printf("\n%s gives to %s", name10, name);
printf("\n%s gives to %s", name16, name8);

printf("\n%s gives to %s", name8, name14);
printf("\n%s gives to %s", name15, name2);
printf("\n%s gives to %s", name, name6);
printf("\n%s gives to %s", name9, name11);
printf("\n%s gives to %s", name12, name16);
printf("\n%s gives to %s", name3, name10);
printf("\n%s gives to %s", name13, name7);
printf("\n%s gives to %s", name5, name1);
printf("\n%s gives to %s", name17, name4);


//integers are %d, characters are %s

printf("\n\nPlease say what number you were, or ");
printf(" press 0 to quit. ");
scanf("%d",&mark);


if(mark <1);
{
printf("\n%s gives to %s", name, name6);
}

if(mark == 2);
{
printf("\nIt Finally works!");
}

return 0;
}
brandcolt is offline   Reply With Quote
Old Feb 25th, 2005, 1:25 PM   #2
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
Im not sure if you are using c or c++. I dont really know C.

But I think your error is the semicolons following the if statements.
__________________
...
Xero is offline   Reply With Quote
Old Feb 25th, 2005, 3:02 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I think the problem is huge redundancy - use arrays!
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 25th, 2005, 3:53 PM   #4
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Yea. Multidimensional arrays would probably help you here. Also, as Xero said, you probably don't want those semicolons after the if statements.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 28th, 2005, 10:31 AM   #5
brandcolt
Newbie
 
Join Date: Jan 2005
Posts: 7
Rep Power: 0 brandcolt is on a distinguished road
Ok Thanks guys I took out the semicolons but it still isn't working. Can someone tell me why the arrays are better than character variables? Also if I change to arrays, do i have to change the scanf parts from %s to something else? Like %c or something? Because I know %d are for integers, and %s are for characters, so what is it for arrays?
brandcolt is offline   Reply With Quote
Old Feb 28th, 2005, 1:41 PM   #6
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
an array of all your names is better so you do not have to repeat the same code 18 times...

#include <stdio.h>
#include <conio.h>

#include <stdlib.h>


int main(void)

{
    char names[18][10];

    char ready[10];
    int mark = 0;
    int count = 0;


    printf("\tSTEWART FAMILY GIFT EXCHANGE\n\n");


    //Gets all the people's names

    while (count < 18 ){
        printf("Enter the name %d.\n", count);
        scanf("%s", names[count]);
        printf("Oh name %d is %s\n", count, names[count]);
        count++;
    }

    count = 0;

    printf("\n\nOk the names will now be ");
    printf("distributed out");
    printf("\n\nType ok when ready\n");
    scanf("%s", ready);

    printf("\n%s gives to %s", names[7], names[3]);
    printf("\n%s gives to %s", names[1], names[9]);
    printf("\n%s gives to %s", names[11], names[5]);
    printf("\n%s gives to %s", names[4], names[15]);
    printf("\n%s gives to %s", names[2], names[17]);
    printf("\n%s gives to %s", names[14], names[12]);
    printf("\n%s gives to %s", names[6], names[13]);
    printf("\n%s gives to %s", names[10], names[0]);
    printf("\n%s gives to %s", names[16], names[8]);

    printf("\n%s gives to %s", names[8], names[14]);
    printf("\n%s gives to %s", names[15], names[2]);
    printf("\n%s gives to %s", names[0], names[6]);
    printf("\n%s gives to %s", names[9], names[11]);
    printf("\n%s gives to %s", names[12], names[16]);
    printf("\n%s gives to %s", names[3], names[10]);
    printf("\n%s gives to %s", names[13], names[7]);
    printf("\n%s gives to %s", names[5], names[1]);
    printf("\n%s gives to %s", names[17], names[4]);


    //integers are %d, characters are %s

    printf("\n\nPlease say what number you were, or ");
    printf(" press 0 to quit. ");
    scanf("%d",&mark);


    if(mark <1)
    {
        printf("\n%s gives to %s\n", names[0], names[6]);
    }

    if(mark == 2)
    {
        printf("\nIt Finally works!\n");
    }

    return 0;
}

I do not understand your bug with both print statements at the end.... as shown... only one of the two will print

Last edited by spydoor; Feb 28th, 2005 at 1:44 PM.
spydoor is offline   Reply With Quote
Old Mar 1st, 2005, 10:37 AM   #7
brandcolt
Newbie
 
Join Date: Jan 2005
Posts: 7
Rep Power: 0 brandcolt is on a distinguished road
Wow ok thanks man! Here's the new code: (Thanks to spydoor)

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>


int main(void)

{
char names[18][10];

char ready[10];
int mark = 0;
int count = 0;


printf("\tSTEWART FAMILY GIFT EXCHANGE\n\n");


//Gets all the people's names

while (count < 18 ){
printf("Enter the name %d.\n", count);
scanf("%s", names[count]);
printf("Oh name %d is %s\n", count, names[count]);
count++;
}

count = 0;

printf("\n\nOk the names will now be ");
printf("distributed out");
printf("\n\nType ok when ready\n");
scanf("%s", ready);

printf("\n%s gives to %s", names[7], names[3]);
printf("\n%s gives to %s", names[1], names[9]);
printf("\n%s gives to %s", names[11], names[5]);
printf("\n%s gives to %s", names[4], names[15]);
printf("\n%s gives to %s", names[2], names[17]);
printf("\n%s gives to %s", names[14], names[12]);
printf("\n%s gives to %s", names[6], names[13]);
printf("\n%s gives to %s", names[10], names[0]);
printf("\n%s gives to %s", names[16], names[8]);

printf("\n%s gives to %s", names[8], names[14]);
printf("\n%s gives to %s", names[15], names[2]);
printf("\n%s gives to %s", names[0], names[6]);
printf("\n%s gives to %s", names[9], names[11]);
printf("\n%s gives to %s", names[12], names[16]);
printf("\n%s gives to %s", names[3], names[10]);
printf("\n%s gives to %s", names[13], names[7]);
printf("\n%s gives to %s", names[5], names[1]);
printf("\n%s gives to %s", names[17], names[4]);


//integers are %d, characters are %s

printf("\n\nPlease say what number you were, or ");
printf(" press 0 to quit. ");
scanf("%d",&mark);


if(mark = 0)
{
printf("\n%s gives to %s\n", names[0], names[6]);
}

if(mark = 1)
{
printf("\nIt Finally works!\n");
}

return 0;
}




Ok But the if statement at the end stil doesnt work! No Matter what number I put in, it just says "It finally works!" Any help?


* I finally got it to work! I had to change the = sign to double equal sign (==) on the IF statements! Thanks for everything guys!

Last edited by brandcolt; Mar 1st, 2005 at 10:49 AM.
brandcolt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC