I'm bored
C-code Basics
Just the basics of C
Any command ends with semi-colon => ;
Libraries
#include <library>
stdlib.h = standard library
stdio.h = input/output library
math.h = for maths
array.h = you won't need here, but it's good to know that it exists
print word
printf("enter letters here\n");
\n = new line
user input (number)
float = ex. 23.455
float n;
scanf("%f", &n);
int = ex. 23
int n;
scanf("%i", &n);
char = symbols, letters
char n;
scanf("%c", &n);
(only one letter input!)
Program Example
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int age;
float number, favnumb;
char letter;
do {
printf("Please enter your age");
scanf("%i",&age);
while(age <0) {
printf("\nError age must be bigger or equal to 0\n please enter age");
scanf("%i",&age); }
printf("\nwhat is your favourite number?\n");
scanf("%f", &favnumb);
printf("\n do you want to repeat the process?");
scanf("%c", &letter);
if(letter == 'y') {
printf("let's start again); }
else if(letter =='Y'){
printf("alright, let's start again); }
else{
do {
printf("please enter y or n");
scanf("%c"&letter);
} while(letter != 'y' || letter != 'Y')
} while (letter == 'y' || letter == 'Y')
printf("Goodbye");
return 0; }
Comments
Displaying 0 of 0 comments ( View all | Add Comment )