Jump to content
  • Advertisement
Sign in to follow this  
MotorBully

I'm new hear,help me in C language(not C++)

This topic is 2427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my first time to public a topic!I really want to exchange the programming technologe with others ,but i have great trouble in talking with others.Because my english is very poor,now,i'm taking a dictionary with my left hand,right hand is on(on or in??damn it) the keyboard,looked ridiculous.I am really want to make friend with people who likes talk with me.Althoule??Althougle?(damn it)(what is "SuiRan")Oh , my god,let me find this word,that..........is "Although",ha!Although the language problem is very bad to me,but the computer is the same, the computer language is the same,such as the C++language.

Now !Show me code where include my question.
#include <stdio.h>
#include <math.h>
void ERROR();
double main()
{
float I;
float S;
int month;
RETURN1:
printf("Input the monthly interest rate(0~100):\n");
scanf("%f",&I);
if(I<=100&&I>=0){}
else
{
ERROR();
goto RETURN1;
}
RETURN2:
printf("Input total deposits(0~5000000000):\n");
scanf("%f",&S);
if(S<=5000000000&&S>=0){}
else
{
ERROR();
goto RETURN2;
}
RETURN3:
printf("Input storage for several months(0~3600):\n");
scanf("%d",&month);
printf("\n");
if(month<=3600&&month>=0){}
else
{
ERROR();
goto RETURN3;
}
double CS;
I = (I/100)+1;
CS = S*(pow(I,month));
printf("%d month later!You have :%f\n",month,CS);
printf("CALCULATING HAS BEEN CLOSED!!!\n");
return 0;
}
void ERROR()


{
printf("Error,Input again!!!\n");
};



The question has come!
if i input not a numer but an Char just like ' a ',The programe will cout the "Error,Input again!!!" again and again, i use the "if "and"else",
"a" is truely out of the range,how can i do now.
just like ....



Input the monthly interest rate( 0 ~100)
a //i input an "a",(not a number)
Error,Input again!!!
Error,Input again!!!
Error,Input again!!!
Error,Input again!!!
Error,Input again!!!
Error,Input again!!!
Error,Input again!!!
.............................. //I cannot stop it unless i close the window;
what is it?How it be that??

Share this post


Link to post
Share on other sites
Advertisement
Hidden
I cannot wait,i am in the other side of the Earth,I am so tired , i have to sleep!I will back tomorrow!
<Ha,My poor english>

Share this post


Link to post
On a failed match scanf() leaves the unmatched characters in the buffer. If you continue to use the same scanf() call without flushing the buffer first it'll try parsing the same input and fail in the same way. In C you can loop getchar() until you read a newline or you can try using fgets() to get rid of the pending input.

Share this post


Link to post
Share on other sites
Wow!So quickly,Very Thanks!"getchar()",good idea ! getchar() can catch the charactor,but what the thing like "?#$%@",i don't sure of that.Is there any function can judge it in uniform.
oh!I have solved the problem ,they are all from ASCALL,,using the char collision to sure a range.
example
char a;
......
if(a<='9'&&a>='0')
{
return true;
}
else
false;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!