Question

Your friend Raphael is an elementary school teacher. He has n students in his class, numbered...

Your friend Raphael is an elementary school teacher. He has n students in his class, numbered 1,2,...,n. On a particularly chilly Wednesday, he decides to lure his students into attending his class by giving away candies to each of them. However, some children are mischievous and take more candies than allotted. The students who get lesser candies thus get sad, and need to be comforted. Therefore, Raphael wants your help in determining the index of the student who is the least happy.

Write a program in C++ that asks the user for an integer n, and then asks the user to input n different integers. Store these integers in an array. Print the index of the student who receives the minimum number of candies.

If more than one student gets the least number of candies, you can print any one of them.

Sample Output:
Please enter the number of students (n): 5
Please enter the number of candies student 1 got: 3
Please enter the number of candies student 2 got: 4
Please enter the number of candies student 3 got: 2
Please enter the number of candies student 4 got: 1
Please enter the number of candies student 5 got: 3

4

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
int main()
{
  
   int n;
  
   //reading number of students
   cout<<"Please enter the number of students (n):";
   cin>>n;
  
   int i=1;
   int min =i,mini;//min index
   int curr;
   while(i<=n)
   {
       cout<<"Please enter the number of candies student "<<i<<" got:";
       cin>>curr;
      
       if(i==1)
       {
           mini=i;
           min =curr;  
       }
       else
       {
           if(curr<min)
           {
               min = curr;
               mini =i;  
           }
              
       }
       i++;
   }
   cout<<mini<<endl;
   return 0;
}

output:

Please enter the number of students (n):5
Please enter the number of candies student 1 got:3
Please enter the number of candies student 2 got:4
Please enter the number of candies student 3 got:2
Please enter the number of candies student 4 got:1
Please enter the number of candies student 5 got:3
4


Process exited normally.
Press any key to continue . . .


//PLS give a thumbs up if you find this helpful, it helps me alot, thanks.

Add a comment
Know the answer?
Add Answer to:
Your friend Raphael is an elementary school teacher. He has n students in his class, numbered...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use java There are n students in a class and n numbered chairs. The instructor has...

    use java There are n students in a class and n numbered chairs. The instructor has assigned a presentation for each student and is going to select the order of presentations by the following scheme. A number m is chosen. Beginning at seat number 1, she counts to m. The student sitting in that seat presents first. Then she starts counting seats again, starting from the next seat, wrapping around at the end, and skipping any student who has already...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • 1) (10 pts) A class has n students, and the ith student has taken si tests....

    1) (10 pts) A class has n students, and the ith student has taken si tests. This information is stored in a file where the first line has the value of n and the following n lines have information about each student. On the ith of these lines, the first value is si. This is followed by si integers, all in between 0 and 100, inclusive, representing the test scores. Here is a sample file: 4 10 100 80 90...

  • JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class....

    JAVA PROGRAMMING PLEASE This lab has three parts: Create an ArrayList class. Create a LinkedList class. Print out the results after testing each of the methods in both of the classes and solving a simple problem with them. Task 1 – ArrayList Class Create an ArrayList class. This is a class that uses an internal array, but manipulates the array so that the array can be dynamically changed. This class should contain a default and overloaded constructor, where the default...

  • Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1...

    Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1 to the Office of Registrar at the end of the semester. Display an introductory paragraph for the user then prompt the user to enter a student record (student ID number and five exam-scores – all on one line). The scores will be in the range of 0-100. The sentinel value of -1 will be used to mark the end of data. The instructor has...

  • you must implement public class Student by following the instructions as follows exactly. You may reference...

    you must implement public class Student by following the instructions as follows exactly. You may reference Chapter 7 for the similar examples to get the ideas and concepts. Each student must have the following 5 attributes (i.e., instance variables): private String   studentID ;              // student’s ID such as                         1 private String lastName   ;                         // student’s last name such as              Doe private String firstName ;             // student’s first name such as            John private double gpa...

  • A university computer science department has a teaching assistant (TA) who helps undergraduate students with their...

    A university computer science department has a teaching assistant (TA) who helps undergraduate students with their programming assignments during regular office hours. The TA’s office is rather small and the TA can help only one student at a time in the office. There are two chairs in the hallway outside the office where students can sit and wait if the TA is currently helping another student. When there are no students who need help during office hours, the TA sits...

  • c program Your teacher want to find out who is the most hardworking student in class!...

    c program Your teacher want to find out who is the most hardworking student in class! They want to input the names according to the order they fell asleep, then print their names in the reverse order. Although you can create an array large enough to store all names, your teacher don’t want to waste our precious memory! The first line of the input is an integer x, which indicate the number of students in class. Then there are x...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT