Program closes

What did I do wrong? This looks similar to one of my other programs, yet once you enter the first input it closes instantly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
#include <stdio.h>

int main( )
{
         for( int a = 1; a < 11; a = a + 1 )
     {
 int a;
 int b;
 int c;
 float x;
 printf("Find d in d=(a^2+b^3+c^4)/(a+b+c).\n");
 
 printf("Enter the value of a.\n");
 scanf("&d",&a);
 
 printf("Enter the value of b.\n");
 scanf("&d",&b);
 
 printf("Enter the value of c.\n");
 scanf("&d",&c);

 x = (a^2+b^3+c^4)/(a+b+c);
 printf("d is equal to %f.\n",x);
 return 0;
}
getchar(); 
}
Is this the exact code you are using? Line 9 is a compiler error for me because you are redeclaring the integer a.

Once you take that out, you can replace the & with % in your &d on lines 16, 19, 22, and I think it will work for you.
o.o my compiler never gave me an error...

And yea, I'm retarded for not seeing the &/% difference thing

Thanks! it works
I'm using Bloodshed Dev
I'm using GNU g++ version 4.8.2. I find that it gives me a lot more warnings/errors that help point out things like that.

You're not retarded - you'll notice things like that more easily as you get more experience. :-)
Topic archived. No new replies allowed.