Join 137,402 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,116 people online right now. Registration is fast and FREE... Join Now!
Currently there are 7 printf statements used to output results. Does anyone know how to modify the program so that there are only 2 printf statements used to produce exactly the same output and if you can could you please post your answer. thanks
CODE
#include <stdio.h>
int main() { int x; int y;
printf( "Enter the first number: "); scanf("%d", &x); printf( "Enter the second number:"); scanf("%d", &y);
printf( "The sum is %d\n" , x + y); printf("The product is %d\n",x * y); printf( "The difference is %d\n", x - y ); printf( "The quotient is %d\n", x / y ); printf( "The modulus is %d\n", x % y );
system ("PAUSE"); return 0;
}
edit: added [code] tags ~ jayman9
This post has been edited by jayman9: 26 Sep, 2006 - 06:39 PM
they are homework, and I've tried to do it and i have modified versions that I've done but I can't seem to figure it out, since it's due tomorrow I was hoping to get some extra help.
That's right, I can't give you the code. I can however, point you in the right direction. Take a look about how you are proceeding, the printf function acts a ceartin way with displaying variables.
Take a look at both your programs, see how you arranged the printf statements? Try doing that even further to fufill the critera of the assignment.
Just keep in mind to use correct % and \ escape characters. %d is what you could use for integers.
This post has been edited by WolfCoder: 26 Sep, 2006 - 06:17 PM
WolfCoder is correct you have one program that you know is syntactically correct. Compare the two programs, more specifically compare similar lines of code. You will notice several problems in the one with the errors. The rest are just typos, which you can determine by comparing to similar code inside that very same program.
thanks guys...and sorry for posting homework questions but I really didn't know what I kept doing wrong...
No worries. We are happy to help you in any way that we can. It is just that when it comes to homework we have to tread carefully. We want people to understand the solutions that members try to provide, not just give them the answers and complete their homework for them.
thanks guys...and sorry for posting homework questions but I really didn't know what I kept doing wrong...
No worries. We are happy to help you in any way that we can. It is just that when it comes to homework we have to tread carefully. We want people to understand the solutions that members try to provide, not just give them the answers and complete their homework for them.
Excellent, you still have 2 errors. One error is a duplicate of another error you already found. The other error, you just need to look at each line carefully. You will see there is a common element to every line of code, except one of them.
Hope that helps.
On a side note, please use [code] tags when you post your code, so as to minimize the amount of room the code will take in your post. If you edit one of your posts you can see where I added the 2 tags. Thanks.