CS 2073, Engineering Programming
|
Answer: You can use the computers in SB 1.02.04 (Science Building), and they have Visual Studio 6.0. They are the ones I used to try out the software for the course. When I get a chance, I'll see if I can find a Visual Studio.net to try out. The "bloodshed" program on the computers uses a link called "Dev-C++" or some such. Anyway, for now the fix is to use SB 1.02.04 if all else fails.
Answer: Sure. You need a "scanf" statement (or something like it) at the end of your program, so that at the end of your the run, everything will pause while it waits for you to enter data. The method I showed in class looked like the following, where you add the stuff in red below.
int main() {
int dummy;
/* the inside of your main function here */
scanf("%d", &dummy);
return 0; /* if you have a return -- it's not needed */
}
Answer:Yeah, sorry. In Visual Studion you need to have the extra include #include <time.h> at the start. I have it now in the sample program.
#include <stdio.h>
void sort(int [ ],int);
int main() {
int dummy;
int number;
int s[20];
int n = 0;
int i;
printf("Please enter some numbers, followed by -1:\n");
for (;;) {
scanf("%i", &number);
if (number == -1) break;
s[n] = number;
n++;
}
for (i = 0; i < n; i++)
printf("%i ", s[i]);
printf("\n");
scanf("%d", &dummy);
return 0;
}
void sort(int s[ ],int n) {
int i,k,now;
for(i = 1; i < n; i++) {
now = s[i];
for(k = i - 1; k >= 0 && now < s[k]; k--)
s[k+1] = s[k];
s[k+1] = now;
}
}
Answer: I believe your only mistake is that you did not call your sort function. From within the main function, after the loop to read and print, you could place your sort funtion in the form sort(s, n); However, you are not allowed to use this method. Instead you must follow the directions and insert each new number in the proper (sorted) location as you read the numbers.