Hello,
Uhm I just started to learn C (It is very fun and challenging) however i have one little question. I cant think of a reason to why the function "printf" is posting 2 times?
Here is the code:
Code:
#include <stdio.h>
int main()
{
int x;
int y;
int v;
int c;
printf( "Please input a value to test the value of X. {Y = ___ + ( x - 4 )}: " );
scanf( "%d", &v );
x = 13; y = v + ( x - 4 );
do {
printf( "Your answer is: %d\n", y);
getchar();
} while (c != 13 ); /* Not actually sure how to use.... explain please? */
}
I know its very basic (just started learning today). Also if you dont mind answering 2 more little questions, please do.
1) I could use "for" instead of "do" right? Whenever I do, i cannot get it to work correctly like i can with "do" however i dont know how to use the "while" function, and i cant find a way to leave that out.
2) Could I use the "while" function to return to the top, to redo the equation if the value returns false, and if true, use printf to say "correct" or whatever? Would that be efficent? Is there another way to do the exact same thing?
Here is a guess I made towards this?
Code:
int c; /* this is the int value ill assign at the beggining, just included so you know that i declared C as a intiger */
printf( "What is your guess for the value of X?: "
scanf( "%d", &c ) }
if ( c = 13 ) {
printf( "Your Correct!\n" ); }
else {
printf( "Please Try Again, Your Incorrect!" ); /* how would i tell it to return to the top if incorrect? */
} while (c != 13 ); /* Not actually sure how to use.... explain please? I need to tell this to return false, then make it return to the top? Is there a more efficent way? */
getchar();
}
Thanks for reading,
hopefully im not breaking any rules?
~Nerix