Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Wrote a code that does not work. Need help. (C Language)

c program

  • Please log in to reply
2 replies to this topic

#1 SaitenHazard


    CC Lurker

  • New Member
  • Pip
  • 7 posts
  • Learning:C

Posted 16 July 2013 - 03:04 AM

What its supposed to do?

Its a simple game. The player gets 10 tries to guess the 'magic number' (predetermined). Every time the player gets it wrong the programs prompts him or her if the 'magic number' is higher or lower the what was guessed.


What I wrote?


#include <stdio.h>
int com(int);
int main()
    int man, tri, ges;
    printf("This is a simulation of the game guess the magic number.\n You have ten tries to guess the number.");
    tri = 1;
    for(man=1; man<11; man++)
          printf("Your guess: ");
          scanf("%d", ges);
          if (com(ges)=0) tri++;
          else {man=12; printf("It took you %d number of tries.", tri);}
    return 0;
int com(ges)
    int num;
    num = 17;
    if(num>ges){ printf("The magic number is greater.\n"); return 0;}
    if(num<ges){ printf("The magic number is smaller.\n"); return 0;}
    if(num=ges){ printf("You have guessed the magic number."); return 1;}


What is the situation now?


I have no idea what I am doing and I cant even understand the debugger anymore.


Thanks in advance.

  • 0

#2 wim DC

wim DC


  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 16 July 2013 - 04:07 AM

I guess you'll want a double '==' here
 if (com(ges)=0)

Edited by wim DC, 16 July 2013 - 04:07 AM.

  • 0

#3 lintwurm


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 261 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, Visual Basic .NET

Posted 16 July 2013 - 04:58 AM

Also, for future reference use the coding blocks to put your code in. They look like 2 angular brackets <>.

  • 0
No harm was done to the world in sending this message, but a few million electrons have been SERIOUSLY inconvenienced...

Also tagged with one or more of these keywords: c, program

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download