Solved

array  and loop

Posted on 1998-02-25
11
247 Views
Last Modified: 2009-12-16
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
Comment
Question by:xyz_hang
  • 6
  • 5
11 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 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

by:jhance
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

by:xyz_hang
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.
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
 

Author Comment

by:xyz_hang
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.
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
 
LVL 32

Expert Comment

by:jhance
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
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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 

Author Comment

by:xyz_hang
ID: 1257400
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
 
LVL 32

Expert Comment

by:jhance
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

by:xyz_hang
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

by:xyz_hang
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

by:xyz_hang
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

by:jhance
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++){
            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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 175
distributed computing in Python 4 114
Need example 5 107
Setting nameservers after res_init fails doing res_query 2 85
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now