Ok my only question is now how come the code below works in ch but not in code blocks?
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int intarray[10];
double doublearray[10];
char string[20];
int uppercount = 0, lowercount = 0;
int i;
int numints, numdoubles;
int negcount, poscount, zerocount;
printf("Enter how many numbers you want to find values for: ");
scanf("%d", &numints);
for (i=0; i< numints; i++)
{
printf("Enter an integer value: ");
scanf("%d", &intarray[i]);
}
/* Then ask for number of double values and read them in using %lf */
printf("How many decimals do you want to find values for: ");
scanf("%d", &numdoubles);
for (i=0; i< numdoubles; i++)
{
printf("Enter an demcimal value: ");
scanf("%lf", &doublearray[i]);
}
/* #3 */
printf("Enter a short character string: ");
scanf("%s", string);
negcount=0;/* initialize the counters*/
poscount=0;
zerocount=0;
for (i = 0; i < numints; i++)
{
if (intarray[i] < 0)
negcount++;
if (intarray[i] == 0)
zerocount++;
if (intarray[i] > 0)
poscount++;
}
printf("you entered: \n %d negative values \n %d positive values \n %d zero values \n", negcount, poscount, zerocount);
/* Do counts for double array */
negcount=0;/* initialize the counters*/
poscount=0;
zerocount=0;
for (i = 0; i < numints; i++)
{
if (doublearray[i] < 0)
negcount++;
if (doublearray[i] == 0)
zerocount++;
if (doublearray[i] > 0)
poscount++;
}
printf("you entered: \n %d negative values \n %d positive values \n %d zero values \n", negcount, poscount, zerocount);
for (i = 0; string[i]; i++)
{
if ((string[i] >= 'A') && (string[i] <= 'Z')) {
uppercount++;}
if ((string[i] >= 'a') && (string[i] <= 'z')) {
lowercount++;}
}
printf("You have %d upper case characters\n",uppercount);
printf("You have %d lower case characters\n",lowercount);
/* print out counter values etc.....*/
system("Pause");
return 0;
}
program in ch
Code:
>ch -u "hw3 tryed to fix errors in ch"
Enter how many numbers you want to find values for: 1
Enter an integer value: 1
How many decimals do you want to find values for: 1
Enter an demcimal value: 1.1
Enter a short character string: HItoU
you entered:
0 negative values
1 positive values
0 zero values
you entered:
0 negative values
1 positive values
0 zero values
You have 3 upper case characters
You have 2 lower case characters
Press any key to continue . . .
code in codeblocks
Code:
>
Enter how many numbers you want to find values for: 1
Enter an integer value: 1
Enter an demcimal value: 1.1
Enter a short character string: HItoU