Skip to content

Commit 418dd71

Browse files
committed
Assignment 2
1 parent aae35ac commit 418dd71

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed

assignment2.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Ava N.
2+
June 29, 2016
3+
4+
1. There can be two or more operators in a single line of program code as long as there is a logical operator seperating the relational operator statements.
5+
6+
2. Syntax errors are incorrect spellings of reserved words or incorrect puncuation. Logical errors give an output that is unexpected or unwanted.
7+
8+
3. 10>= && 10<25 && 10 !=12
9+
true true true
10+
answer=true
11+
12+
4. The given example is incorrect because there cannot be more then one relational operator in a single statement. This is only allowed, however, when there is a logical operator inbetween them. The statement can instead look like this: 0<x && x<15. This represents what x has to be equal to under these circumstances.
13+
14+
5. Example i is invalid because 'then' should not be written. Example ii is invalid because there needs to be parentheses around a>b. Example iii is valid. Example iv is invalid because there needs to be a semicolon(;) after c=0.

cal

8.56 KB
Binary file not shown.

calculator.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*Ava N.*/
2+
#include <stdio.h>
3+
4+
int main()
5+
6+
{
7+
float y; /*first number*/
8+
float z; /*second number*/
9+
float a; /*answer*/
10+
char x; /*operation*/
11+
12+
printf("Choose one of the following: +, -, *, /, or % \n");
13+
scanf("%c", &x);
14+
printf("Pick a number \n");
15+
scanf("%f", &y);
16+
printf("Pick another number \n");
17+
scanf("%f", &z);
18+
switch(x)
19+
{
20+
case '+':
21+
a=y+z;
22+
printf("The addition is: \n", x);
23+
break;
24+
case '-':
25+
a=y-z;
26+
printf("The subtraction is: \n", x);
27+
break;
28+
case '/':
29+
a=y/z;
30+
printf("The division is: \n", x);
31+
break;
32+
case '*':
33+
a=y*z;
34+
printf("The multiplication is: \n", x);
35+
break;
36+
case '%':
37+
a=(int)y%(int)z;
38+
printf("The percentage is: %f\n", x);
39+
break;
40+
default:
41+
printf("Your response was invalid. Please try again.");
42+
}
43+
44+
printf("%f \n", a);
45+
46+
return 0;
47+
48+
}

input

8.56 KB
Binary file not shown.

randnum

8.64 KB
Binary file not shown.

randnum.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*Ava N.*/
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <time.h>
6+
7+
int main (){
8+
srand(time(0));
9+
int r=rand() %10 + 1;
10+
/*printf("%d", r);*/ /*This was checking to make sure that only numbers 1-10 were being generated as a random.*/
11+
int g; /*g=user's guess*/
12+
printf("Can you guess what random number between 1-10 the computer has generated? \n");
13+
scanf("%d", &g);
14+
if (g==r){
15+
printf("You're a genius! That was the correct answer! \n");
16+
}
17+
18+
else if(g>r){
19+
printf("You're number was too high! Try again next time. \n");
20+
}
21+
22+
else if(g<r){
23+
printf("You're number was too low! Try again next time. \n");
24+
}
25+
26+
else {
27+
printf("You entered an incorrect value. Try again next time. \n");
28+
}
29+
30+
return 0;
31+
}

user_input.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*Ava N.*/
2+
#include <stdio.h>
3+
4+
int main() {
5+
6+
float n; /*n for number*/
7+
printf("Write an integer and I will guess whether it is positive or negative! \n");
8+
scanf("%f", &n);
9+
10+
11+
if(n>0)
12+
{
13+
printf("You chose a positive number! \n");
14+
}
15+
16+
else if(n<0)
17+
{
18+
printf("You chose a negative number! \n");
19+
}
20+
21+
else if(n==0)
22+
{
23+
printf("You chose zero! \n");
24+
}
25+
26+
else{
27+
printf("You did not choose a number!");
28+
}
29+
30+
return 0;
31+
}

0 commit comments

Comments
 (0)