C/c

Advertisement


Question
hello. i dont know whats wrong with this code. i am trying to make a simple program to help counting score in darts. the code is not finished yet i will insert a break in the loop later. but for now i want to make sure that the loop works infinately. at this moment it does not. i am using a gcc compiler in ubuntu 13.10 to compile it. could you please help me. thank you for your time.

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

int main()
{
int score;
unsigned char newscore;
int num;
score=301;

for( ; ; ){
  printf("what did you get?\n");
  scanf("%s",newscore);
  num=atoi(newscore);
  score=score-num;
printf("now your score is %d. \n",score);
}
return(0);
}

Answer
Hi Anthony,

Please be specific about your error. It is not executing infinitely means exactly what, How many time its running? Is it breaking in between? Or it is not going inside for loop?

Note : Have you tried with while(true) instead of for(;;). Try it once.

Thanks & Regards,
Kedar Desai  

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Kedar Desai

Expertise

You can ask me any questions about C and c++

Experience

I don't have practical experience. But i have knowledge about C as I belong to IT field since last 5 years.

Education/Credentials
I an studying in MCA from Maharashtra (Mumbai University)

©2016 About.com. All rights reserved.