• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

array and loop

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
xyz_hang
Asked:
xyz_hang
  • 6
  • 5
1 Solution
 
jhanceCommented:
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
 
jhanceCommented:
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
 
xyz_hangAuthor Commented:
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.
I still have some questions about this program:
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).

Here's about question 2:

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
.        .            .
.        .            .
.        .            .
please enter quiz 10'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.)

Thanks in advance

Please send it to me by tomorrow noon!
0
Managing Security & Risk at the Speed of Business

Gartner Research VP, Neil McDonald & AlgoSec CTO, Prof. Avishai Wool, discuss the business-driven approach to automated security policy management, its benefits and how to align security policy management with business processes to address today's security challenges.

 
xyz_hangAuthor Commented:
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.
I still have some questions about this program:
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).

Here's about question 2:

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
.        .            .
.        .            .
.        .            .
please enter quiz 10'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.)

Thanks in advance

Please send it to me by tomorrow noon!
0
 
jhanceCommented:
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
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.

loop.c
Microsoft (R) 32-Bit Incremental Linker Version 5.10.7303
Copyright (C) Microsoft Corp 1992-1997. All rights reserved.

/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
 
xyz_hangAuthor Commented:
It still does not work correctly. i typed as same as what Jhance give me.

I would ask another expert to give me a correct answer about question 1 and 2.

Thanks
P.S. I use MS developer stidio VISUAL C++
0
 
jhanceCommented:
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
 
xyz_hangAuthor Commented:
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
 
xyz_hangAuthor Commented:

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
 
xyz_hangAuthor Commented:

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
 
jhanceCommented:
#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++){
            grades[i] = 0;
      }

      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;
            }

            grades[i] = atoi(buffer);
      }

      for(j=0; j<i; j++){
            if(grades[j] > highest){
                  hindex = j;
                  highest = grades[j];
            }
      }

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

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now