ClioSport.net

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

Anyone here program in C?

Car  Saxo VTS
Hi.

I'm doing an assingment for college but currently stuck on an IF staement within my program.

Basicaly instead of running the IF the staement the program seems to ignore it and go straight to the end of the program (Press any key to continue).

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char surname[30];
char initial[1];
char dob[8];
int choice;

printf("Please enter your surname: ");
scanf("%s", surname);
printf("Please enter your initial: ");
scanf("%s", initial);
printf("Please enter your date of birth in the DD/MM/YYYY format: ");
scanf("%d", dob);
system("cls");
printf("1 - Arithmetic \n");
printf("2 - Conversion \n");
printf("3 - Result \n");

printf("Please choose a number to continue: ");
scanf("%d",choice);

if(choice==1)
{
system ("cls");
printf("You chose 1");
}
else if(choice==2)
{
system ("cls");
printf("You chose 2");
}
return(0);
}

It's fine up until the first part of the IF staement bu then on key press the program quits.

I'm very new to C so appolgies if the program is a bit crappy :D

Any ideas? Cheers.
 
That is all the code!

Like I say, was working finr untill I put the IF staement in.

This is C, not C++ I'm doing btw.
 
it wont work as your not telling it what to do after the if statement runs, it has the answer but cant do anything with it.
 
Well I'm asking it to print their corresponding choice to the screen...or so I thought.

if(choice==1)
{
system ("cls");
printf("You chose 1");
}
else if(choice==2)
{
system ("cls");
printf("You chose 2");
}
return(0);
}

Surely that is telling it 'IF they choose 1 then print to screen "You chose 1" etc'?

Gay programming :p
 
Yeah it should work ok, sorry missed the printf

Does it actually print to screen before it closes

After the IF statement you have

return(0);

Try it without the brackets.
 
programming suck balls. have to do it in my course.

dont know why any1 wud want to be a computer programmer.
 
your scanf is wrong, should be passing a pointer to "choice" not the value.
 
Ahh, Programming, brings back happy memories

_40429517_selfharm203.webp
 
Back
Top