c - Program stops working at first scanf -


i have been working on while , can't figure out. supposed determine cost of auto insurance each family member based on ages. need able pass ageadd function family members age , possibly count (to keep track of member is), , calculate cost , print out me.

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h>  void ageadd(int);  int main() {  int age, i, o, count;    count = 1; printf("enter number of family members: "); scanf("%d", o);  (i = 0; < o; i++) {      printf("enter age family member %d: ", count);      scanf("%d", &age); \\program crashes here      ageadd(age);      count++; }    return 0;   } 

once reach first scanf program stops working, i'm confused why. can use getchar there instead?

void ageadd(int a) { int sum1, sum2, sum3;   if (a >= 16 && <= 19) {     sum1 = 1000 + (1000 * 15 / 100);     printf("the cost family member %d \n", sum1);  } if (a >= 20 && <= 24) {     sum2 = 1000 + (1000 * 5 / 100);     printf("the cost family member %d \n", sum2);  } if (a >= 25) {     sum3 = 1000 - (1000 * 5 / 100);     printf("the cost family member %d \n", sum3); }   } 

here ageadd method doubt there's of problem here.

fix first scanf call (you need pass pointer):

scanf("%d", &o);

put space between subsequent scanf calls:

scanf(" %d", &age);

this passes on newline character entered on previous iteration.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -