Author Topic: Help me with C?  (Read 346 times)

Code: [Select]
#include<stdio.h>

int main(void) {
    int userAge;
    printf("How old are you?");
    scanf("%d" , userAge);
    if(userAge < 18) {
               printf("You cannot vote. You are too young.");
    } else {
               printf("You are old enough to vote".)
    getchar();
    getchar();
}

I tried to compile and run this, but whenever I input my age it crashes. Anyone see what I did wrong?

-snip-
I tried to compile and run this, but whenever I input my age it crashes. Anyone see what I did wrong?
I have never heard of stdio.h, but I see what you are trying to do. This is how I would do it:
Code: [Select]
#include<iostream>

void main() {
    int userAge;
    printf("How old are you?");
   cin >> userAge;
    if(userAge < 18) {
               printf("You cannot vote. You are too young.");
    } else {
               printf("You are old enough to vote".)
}

Uhh he said C, not C++
The standard i/o for C is stdio.h
for C++ it's iostream
Correct me if I'm wrong

also cin isn't in C

Uhh he said C, not C++
The standard i/o for C is stdio.h
for C++ it's iostream
Correct me if I'm wrong

also cin isn't in C
Yeah you're right

you need an ampersand (&) before userAge in the scanf or it crashes.