Where in the bluest blue hell is the problem?! @#$%^!
Posted 26 March 2013 - 07:04 PM
Where in the bluest blue hell is the problem?! @#$%^!
...you can achieve immortality, simply by doing one great thing...
Posted 26 March 2013 - 07:39 PM
Posted 26 March 2013 - 07:59 PM
Ok it seems that it's working now. I had added two more characters in the while command by mistake. Thanks for the help anyway Ellanios.
But! Now i have another problem. The first turn works great. During the second turn, it excecutes the "printf("Give one of these: + - /.n");" and the "scanf("%c",&c);" commands, but it doesn't wait for the user to input the character! Then it excecutes the "printf("Give an integer.n");" and the "scanf("%d",&a);" command and waits for the user to input an integer.
In a few words, it bypasses the "scanf("%c",&c);" command.
...you can achieve immortality, simply by doing one great thing...
Posted 26 March 2013 - 08:22 PM
Well, my C programming skills are very rusty but, I think It probably has to do with the while statement.
The variable check shouldn't be in the while statement.
Try setting While(1) so to keep the loop forever.
Do you know how to use switch() case statement? I think is more neat way to write this program.
Posted 26 March 2013 - 08:36 PM
#include <stdio.h>main(){ char c; int result,a,b; while (1) { printf("Give one of these: + - /.n"); scanf("%c",&c); printf("Give an integer.n"); scanf("%d",&a); printf("Give another integer.n"); scanf("%d",&b ); if (c=='+') result=a+b; else if(c=='-') result=a-b; else result=a/b; printf("%d %c %d = %d",a,c,b,result); }return 0; }
switch() case statement?Do you mean the "case" command which has similar function to the "if" command?
Exactly. When I had to do a similar program, I did it that way.
Posted 26 March 2013 - 09:04 PM
Damn this fucking C is always pain in the ass. I used to be good in C only to impress my hot professor cause I wanted to pwn her.
But it's been a while since then (5-6 years) so now I can't remember shit.
Let me see if I can find the code of my calculator program.
Posted 26 March 2013 - 09:10 PM
After about half an hour googling, i found this command: fflush(stdin);
I added it above the "printf("Give one of these: + - /.n");" command inside the "while" command.
Finally the bypassing has stopped.
Now i'm gonna create three different functions, so to replace the "result=a+b;", "result=a-b;" and "result=a/b;" commands inside main().
...you can achieve immortality, simply by doing one great thing...
Posted 26 March 2013 - 09:22 PM
"I used to be good in C only to impress my hot professor cause I wanted to pwn her."
lol hahaha
You lucky boy! My professor is a man, with plait, heavy voice and a T-shirt with an air force stamp on it. lol
...you can achieve immortality, simply by doing one great thing...
Posted 26 March 2013 - 09:35 PM
I couldn't find the code of my calculator program but it was something like that:
#include <stdio.h>main(){int operation=0,result=0,a=0,b=0; //It's a good practice to initialize the variablesprintf("Select 1 for Addition, 2 for Subtraction, 3 for Division.n");scanf("%d",&operation);switch(operation){case 1:{printf("Give the first number.");scanf("%d",&a);printf("Give the second number.");scanf("%d",&b);result=a+b;printf("The sum is %d.n", result);break;}case 2:{printf("Give the first number.");scanf("%d",&a);printf("Give the second number.");scanf("%d",&b);result=a-b;printf("the remainder is %d.n", result);break;}case 3:{printf("Give the first number.");scanf("%d",&a);printf("Give the second number.");scanf("%d",&b);result=a/b;printf("The quotient is %d.n", result);break;}default:{printf("You have input an invalid number. Try again.n");} }//End of switchreturn 0;}
I just wrote this code after a 6 year hiatus so, forgive any mistakes.
Your thread brought me some good memories in my mind.
Posted 27 March 2013 - 06:49 AM
"I used to be good in C only to impress my hot professor cause I wanted to pwn her."
lol hahaha
You lucky boy! My professor is a man, with plait, heavy voice and a T-shirt with an air force stamp on it. lol
I will be goin to University in Octobre, and there is one Prof, pretty hot (not a man lol) and one Prof , age around 465 years. Lets hope i dont get Methusalem
Posted 30 March 2013 - 11:06 AM
I will be goin to University in Octobre, and there is one Prof, pretty hot (not a man lol) and one Prof , age around 465 years. Lets hope i dont get Methusalem
lol
Well, according to my teacher's words, the program is the same for both C and C++. The only different is the compiler. We use this program: Link
And we started with C++ the first 6 months. Now we are studying C. Then we will study Java too.
...you can achieve immortality, simply by doing one great thing...
0 members, 1 guests, 0 anonymous users