User input crashes cmd?

Hello all, I'm new here, and have just recently started programming in C++ at university. I was wondering if you guys could help me with a problem I can't seem to figure out. I get no compile errors whatsoever, and it runs fine...until the user inputs their first bit of data, and hits the enter key. After that, the cmd window crashes horribly.

I've tried googling this issue, but haven't found the answer to my problem. I appreciate any help ya'll can offer.

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
31
32
33
34
35
36
37
38
#include <stdio.h>

int main()
{
    
/* Initializing Variables */
   int dummy_var;
   int volt = 100;
   int miles = 100;
   int power = 100;
   int ch;
   float r, total_r, current, loss;
    
/* User Input */
   for(dummy_var = 0; volt != 100 || volt !=200; dummy_var++){
                 printf("How many volts are being transmitted? (100 or 200)\n");
                 scanf("%d", volt);
   }
        
   for(dummy_var = 0; miles != 20 || miles != 40 || miles != 60 || miles != 80 || miles != 100; dummy_var++){
                 printf("How many miles is the current traveling? (20, 40...100)\n");
                 scanf("%d", miles);
   }

   r = 0.05/miles;
   current = power/volt;
   total_r = r*miles;
   loss = (current*current)*total_r;
           
   printf("The power lost over %d miles is %f watts\n\n", miles, loss);
           
   while ((ch = getchar()) != '\n' && ch != EOF);
   {
         printf ("Press enter...");
         getchar ();
         return 0;
   }
}
you have to put the & operator before the variable when using scanf

like this
scanf("%d", &volt);

you can take a look at this...
http://www.cplusplus.com/reference/cstdio/scanf/
Oh my god....I can't believe I missed such a tiny thing. >< That's what I get for not sleeping for three days (Not by choice, got mad insomnia). Thank you so much, you're a life-saver *hugs*

Still had to scrap and redo this in the end though, since I realized that my instructor wanted no user input, and my or statements made my for loops loop forever. I've been so fail at programming this week. Then again, I have lost my home, my job, and am currently stressed out trying to find a new place to live. >_<
Last edited on
Topic archived. No new replies allowed.