So here's my program, I'm fairly sure the problem is in the beginning, as I've tried removing entirely the first for loop, and it said that i was 205837 or something, it changed every time.
As it is right now, when I run the program, it asks for the first questions (How many divisions do you want to make?) and then closes instantly whatever I enter.
Now what I don't understand is, EVEN IF my for loop wouldn't work at all, why wouldn't the scanf end at the end prevent it from just closing?
I am COMPLETELY new to C programming btw, I just started studying Computer Science in University. Also I'm from Quebec, hence the french in the program.
The point is basically to manually divide a number of numbers simply by using substractions and ...well shifts? I don't really know how to call them in English, but moving moving bits in a variable.
Code:
#include "stdafx.h"
#include <stdio.h>
int main ()
{
//division
unsigned short a, b, diff, reste, end;
int valida, validb, i, u, nb;
printf("Combien de divisions voulez-vous effectuer?");
scanf("&d", &nb);
nb = nb + 1; //Pour que la boucle for fonctionne et que le i affiche le bon numéro de dividende/diviseur.
for ( i = 1 ; i < nb ; i++ )
{
do
{
printf("Entrez le dividende %d (valeur entre 0 et 255) : ", &i);
scanf("%d", &valida);
}
while (valida < 0 || valida > 255);
a = valida;
do
{
printf("Entrez le diviseur %d (valeur entre 0 et 255) : ", &i);
scanf("%d", &validb);
}
while (validb < 0 || validb > 255);
b = validb;
b = b << 4;
for ( u = 1 ; u <= 3 ; u++ )
{
a = a << 1;
if (a >= b)
{
a = a - b;
a = a + 1;
}
}
}
printf ("Résultat: %d", &a);
scanf ("%hd", &end); //Inutile, seulement pour ne pas que le programme se ferme
return 0;
}