Welcome to Dream.In.Code
Become a C++ Expert!

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!




DevC++ Help

2 Pages V  1 2 >  
Reply to this topicStart new topic

DevC++ Help

Blazin
26 Sep, 2006 - 05:49 PM
Post #1

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Blazin
RE: DevC++ Help
26 Sep, 2006 - 05:59 PM
Post #2

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
Another question....can someone modify this. There are 8 syntax (grammar) errors in the program I just can't figure it all out.
CODE

/* Program Order */

#include <stdio.h>

int main()
{
/* define variables */
   int w;
   int x;
   int y;
   in z;
   int wsqr, xcub;
   float average;
  
   printf( "Enter four numbers: " );
   scanf( "%d%d%d%d", &w, x, &y, &z );
  
   average = w + x + y + z / 4;
   printf("Average is %f /n", average)

   printf("The first number is %d/nThe second number is %d\n",w,x);
   printf("The third number is %s\n",y);
   printf(The fourth number is %d\n",z);

   wsqr = w * w;
   xcub = x * x * x;
   printf("w squared is %d and x cubed is %d\n",wsqr, cub);

   system("pause");
   return 0; /* indicate successful termination */

} /* end main */


edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: DevC++ Help
26 Sep, 2006 - 06:07 PM
Post #3

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,618



Thanked: 8 times
Dream Kudos: 1450
My Contributions
Instead of /n try using \n (backslash, not forward slash).

You forgot the 't' in int that defines 'z' as a variable integer.

In the scanf statement, you forgot the ampersand before x.

In your average formula, use :
CODE
average = (w + x + y + z)/4;

(Put the parenthesis around the addition to have the correct formula.
Keep in mind the order of operations.

hope that helps you.

This post has been edited by WolfCoder: 26 Sep, 2006 - 06:11 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: DevC++ Help
26 Sep, 2006 - 06:11 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
These sound like homework questions. This site has a policy concerning questions related to homework assignments. Please review the forum rules.

Forum rules can be found here.
User is offlineProfile CardPM
+Quote Post

Blazin
RE: DevC++ Help
26 Sep, 2006 - 06:14 PM
Post #5

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
QUOTE(jayman9 @ 26 Sep, 2006 - 07:11 PM) *

These sound like homework questions. This site has a policy concerning questions related to homework assignments. Please review the forum rules.

Forum rules can be found here.



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.
User is offlineProfile CardPM
+Quote Post

WolfCoder
RE: DevC++ Help
26 Sep, 2006 - 06:15 PM
Post #6

ギュウ~
Group Icon

Joined: 5 May, 2005
Posts: 3,618



Thanked: 8 times
Dream Kudos: 1450
My Contributions
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
User is offlineProfile CardPM
+Quote Post

Blazin
RE: DevC++ Help
26 Sep, 2006 - 06:22 PM
Post #7

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
thanks guys...and sorry for posting homework questions but I really didn't know what I kept doing wrong...
User is offlineProfile CardPM
+Quote Post

Jayman
RE: DevC++ Help
26 Sep, 2006 - 06:24 PM
Post #8

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Blazin
RE: DevC++ Help
26 Sep, 2006 - 06:29 PM
Post #9

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
this is what i have right now
CODE

/* Program Order */

#include <stdio.h>

int main()
{
/* define variables */
   int w;
   int x;
   int y;
   int z;
   int wsqr, xcub;
   float average;
  
   printf( "Enter four numbers: " );
   scanf( "%d%d%d%d", &w, &x, &y, &z );
  
   average = (w + x + y + z)/4;
   printf("Average is %d /n", average)

   printf("The first number is %d\nThe second number is %d\n",w,x);
   printf("The third number is %d\n",y);
   printf("The fourth number is %d\n",z);

   wsqr = w * w;
   xcub = x * x * x;
   printf("w squared is %d and x cubed is %d\n",wsqr, xcub);

   system("pause");
   return 0; /* indicate successful termination */

} /* end main */


edit: added [code] tags ~ jayman9
User is offlineProfile CardPM
+Quote Post

Jayman
RE: DevC++ Help
26 Sep, 2006 - 06:30 PM
Post #10

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE(Blazin @ 26 Sep, 2006 - 07:22 PM) *

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. smile.gif
User is offlineProfile CardPM
+Quote Post

Blazin
RE: DevC++ Help
26 Sep, 2006 - 06:41 PM
Post #11

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 10


My Contributions
QUOTE(jayman9 @ 26 Sep, 2006 - 07:30 PM) *

QUOTE(Blazin @ 26 Sep, 2006 - 07:22 PM) *

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. smile.gif


it is more helpful, so I agree with you.
User is offlineProfile CardPM
+Quote Post

Jayman
RE: DevC++ Help
26 Sep, 2006 - 06:46 PM
Post #12

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 45 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE(Blazin @ 26 Sep, 2006 - 07:29 PM) *

this is what i have right now
CODE

/* Program Order */

#include <stdio.h>

int main()
{
/* define variables */
   int w;
   int x;
   int y;
   int z;
   int wsqr, xcub;
   float average;
  
   printf( "Enter four numbers: " );
   scanf( "%d%d%d%d", &w, &x, &y, &z );
  
   average = (w + x + y + z)/4;
   printf("Average is %d /n", average)

   printf("The first number is %d\nThe second number is %d\n",w,x);
   printf("The third number is %d\n",y);
   printf("The fourth number is %d\n",z);

   wsqr = w * w;
   xcub = x * x * x;
   printf("w squared is %d and x cubed is %d\n",wsqr, xcub);

   system("pause");
   return 0; /* indicate successful termination */

} /* end main */


edit: added [code] tags ~ jayman9



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. wink2.gif

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.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/5/08 03:12AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month