Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# array  and loop

Posted on 1998-02-25
Medium Priority
290 Views
Here are litter 2 questions:

1. write a program that prompts the user to enter a string of at least 35 characters and spaces making up a full sentence. The program should output the number of vowels(a,e,i,o,u) contained in the string: For example, the preceding sentence contains 26 vowels.(50 points)

2. A grammar shool teacher wants to have a program that allows her to enter up to 10 grades ranging from 0 to 100 and gave the program report the highest quiz grade and the quiz numbert on which the student scores the highest grade. if there are several quiz grades on which the student made the same score, the program should display the quiz number of the first such quiz.(100 points)

Thanks
0
Question by:xyz_hang
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 5

LVL 32

Accepted Solution

jhance earned 400 total points
ID: 1257395
Here's an answer to the first part:

#include <stdio.h>
#include <string.h>

void main(void)
{
char string[256];
char vowels[] = "aeiou";
char counts[5] = {0, 0, 0, 0, 0};
int i, j;

printf("Enter the string:");
gets(string);

printf("Counting: %s\n", string);

for(i=0; i<strlen(string); i++){
for(j=0; j<strlen(vowels); j++){
if(string[i] == vowels[j]){
counts[j]++;
}
}
}

for(i=0; i<strlen(vowels); i++){
printf("There are %d of the letter %c\n", counts[i], vowels[i]);
}
}
0

LVL 32

Expert Comment

ID: 1257396
How about some additional information on the second part, it's not clear.  Do you want the data stored in a file?  To report the sutdent's name, there has to be more entry than just the quiz score.  There needs to be at least 3 entries, the name, the quiz number, and the score on that quiz.  Or am I misunderstanding your question?
0

Author Comment

ID: 1257397
Hi, jhance;

Nice to write to you again.I have received your part one answer, but unforturnitely it does not work quite well. First of all, I got two warnings saying" < is mismatch". Second, the counter always counts wrong number. Third, the words "Counting" would not appear on screen. Fourth, this program is infinite loop.
1) char string[256]: what does this 256 number means here.
2) can you use other function instead of strlen()? I don't understand this function because I have not learned it yet.
3) Can you give me a revised program ( question 1 and 2)on Thurday morning( before 12:00).

I am sorry I couldn't give you more information about this question, because I got this printout-question from my teacher and I coundn't reach her. I am not quite sure this question too( English is not my native language), but anyway, from my understanding, I guess we just need to  input quiz scores, the printout format would be like following:

please enter quiz 1 's score: XXX
please enter quiz 2's score: XXX
.        .            .
.        .            .
.        .            .

The highest score is quiz XX : XXX

(if there are several  quizes have  some highest score, show the first one, please don't forget to use a special letter to quit input loop in order to print out the result.)

Please send it to me by tomorrow noon!
0

Author Comment

ID: 1257398
Hi, jhance;

Nice to write to you again.I have received your part one answer, but unforturnitely it does not work quite well. First of all, I got two warnings saying" < is mismatch". Second, the counter always counts wrong number. Third, the words "Counting" would not appear on screen. Fourth, this program is infinite loop.
1) char string[256]: what does this 256 number means here.
2) can you use other function instead of strlen()? I don't understand this function because I have not learned it yet.
3) Can you give me a revised program ( question 1 and 2)on Thurday morning( before 12:00).

I am sorry I couldn't give you more information about this question, because I got this printout-question from my teacher and I coundn't reach her. I am not quite sure this question too( English is not my native language), but anyway, from my understanding, I guess we just need to  input quiz scores, the printout format would be like following:

please enter quiz 1 's score: XXX
please enter quiz 2's score: XXX
.        .            .
.        .            .
.        .            .

The highest score is quiz XX : XXX

(if there are several  quizes have  some highest score, show the first one, please don't forget to use a special letter to quit input loop in order to print out the result.)

Please send it to me by tomorrow noon!
0

LVL 32

Expert Comment

ID: 1257399
1)"< is mismatch", where is this happening.  The only places where this is used are numeric comparisons in the for loops.  Are you forgetting to include string.h?

2) counter counts wrong?  There is no variable counter.

3) Counting: does appear on the screen, see output below.

4) This program is NOT an infinite loop.  It's runs only once!

Here is what I get when I run it.  If you're having trouble please post the actual error message.

C:\temp>cl loop.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for 80x86

loop.c
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303

/out:loop.exe
loop.obj

C:\temp>loop
Enter the string:this is a test
Counting: this is a test
There are 1 of the letter a
There are 1 of the letter e
There are 2 of the letter i
There are 0 of the letter o
There are 0 of the letter u

C:\temp>

0

Author Comment

ID: 1257400
It still does not work correctly. i typed as same as what Jhance give me.

Thanks
P.S. I use MS developer stidio VISUAL C++
0

LVL 32

Expert Comment

ID: 1257401
Why don't use post what your compiler is telling you?  I too amusing VC++ and you see the output posted above.  It shows both the compilation AND running of this program.  I'd suggest that if you typed it in, you have made a mistake.  Why don't you copy it out of the window above and paste it into your editor?
0

Author Comment

ID: 1257402
Hi,Jhance
I feel very sorry that I made a typing mistake, now it runs very good.
Would you give me a part 2 answer as soon as possible I really need it tonight.

Thanks
0

Author Comment

ID: 1257403

ERGENT:

I really need my part 2 question done by 7:00 pm tonight ( now is 6:00pm). is there anybody can do it for me.
0

Author Comment

ID: 1257404

URGENT:

I really need my part 2 question done by 7:00 pm tonight ( now is 6:00pm). is there anybody can do it for me.
0

LVL 32

Expert Comment

ID: 1257405
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void main(void)
{
int grades[10], i, j, highest = 0;
int hindex = 0;
char buffer[256];

for(i=0; i<10; i++){
}

for(i=0; i<10; i++){
printf("Enter quiz %d's score (or Q to quit): ", i+1);
gets(buffer);
printf("\n");

if(buffer[0] == 'q' || buffer[0] == 'Q'){
break;
}

}

for(j=0; j<i; j++){
hindex = j;
}
}

printf("The highest was quiz %d : %d\n", hindex+1, highest);
}
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were smallâ€¦
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to useâ€¦
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
###### Suggested Courses
Course of the Month4 days, 8 hours left to enroll