Question

Hi so we have 4 labs in our introduction to c++ class for this week and...

Hi so we have 4 labs in our introduction to c++ class for this week and this is the only exercise that I couldn't understand thank you guys

//Lab exercise 4: //Ask the user to input 10 probabilities (numbers between 0 and 1).

Then output the index(es) of the number(s) with highest probability. //Example input: 0.8 0.8 0.8 1 1 1 1 1 0.8 0.8 //Example output: 3 4 5 6 7

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
using namespace std;
int main()
{
        int i;
        float array[10],max=0;
        cout<<"Enter The Probabilities(0 to 1)"<<endl; //taking input from user
        for(i=0;i<10;i++)
        {
        cin>>array[i];
        if(!(array[i]>=0 && array[i]<=1))         //condition checking for whether entered value is in between 0 to 1 
        {
        cout<<"Invalid value......please enter values between 0 to 1"<<endl;    // if not in between 0 to 1 then return will terminate the program;
        return 0;
        }
        if(max<array[i])
        {
                max=array[i];            //storing maximum value in max variable;
        }
        }
        cout<<"Index values of The Array where Maximum value present"<<endl;
        for(i=0;i<10;i++)
        {
        if(max==array[i])           //searching for index value which contains  max value;
        {
        cout<<i<< " ";      
        }       
        }
        return 0;
}

output

Add a comment
Know the answer?
Add Answer to:
Hi so we have 4 labs in our introduction to c++ class for this week and...
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
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
ADVERTISEMENT