Answer:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
const int NUM_VALS = 4;
vector<int> userValues(NUM_VALS);
int i = 0;
int matchValue = 0;
int numMatches = -99; // Assign numMatches with 0 before your for loop
userValues.at(0) = 2;
userValues.at(1) = 2;
userValues.at(2) = 1;
userValues.at(3) = 2;
matchValue = 2;
numMatches=0;
//loop to iterate elements of userValues
for(int i=0; i<NUM_VALS; i++)
{
//check the matchValue with every element of the userValues using index
if(userValues.at(i)==matchValue)
numMatches++;
}
//STUDENT CODE
//print the result
cout << "matchValue: " << matchValue << ", numMatches: " << numMatches << endl;
return 0;
}
Explanation:
#include
#include
using namespace std;
int CountCharacters(char userChar, string userString){
int result = 0;
for(int i = 0;i if(userString[i] == userChar){
result++;
}
}
return result;
}
int main(){
string userString;
char userChar;
cin>>userChar>>userString;
cout< return 0;
}
Answer:
Desired C++ Program with proper comment is given below
Explanation:
#include<iostream>
using namespace std;
//main function
int main()
{
int totalMiles = 0;
int remainingMiles = 0;
double amt = 0;
//taking input from user regarind total miles
cout<<"Enter the total miles: "<<endl;
cin>>totalMiles;
//if-else condition to do the calculation
if(totalMiles<=100)
{
amt = totalMiles*.25;
}
else
{
remainingMiles = totalMiles - 100;
amt = 100*.25 + remainingMiles*.15;
}
cout<<"The total amount is: "<<amt<<endl;
}