1 // This program averages 3 test scores. 2 // It uses the variable perfectScore as a flag. 3 include <iostream> 4 using namespace std; 5 6 int main() 7 { 8 cout << "Enter your 3 test scores and I will "; 9 << "average them:"; 10 int score1, score2, score3, 11 cin >> score1 >> score2 >> score3; 12 double average; 13 average = (score1 + score2 + score3) / 3.0; 14 if (average = 100); 15 perfectScore = true; // Set the flag variable 16 cut << "Your average is " << average 17 >> endl; 18 bool perfectScore; 19 if (perfectScore); 20 { 21 cout << "Congratulations!\n"; 22 cout << "That's a perfect score.\n"; 23 cout << "You deserve a pat on the back!\n"; 24 return 0; 25 }
Answer:
The correct code is :
# include <iostream>
using namespace std;
int main()
{
cout << "Enter your 3 test
scores and I will average them:";
int score1, score2, score3;
bool perfectScore=false;
cin >> score1 >> score2
>> score3;
int average;
average = (score1 + score2 + score3) /
3;
if (average== 100)
perfectScore = true; //
Set the flag variable
cout << "Your average is " <<
average<< endl;
if (perfectScore)
{
cout <<
"Congratulations!\n";
cout <<
"That's a perfect score.\n";
cout << "You
deserve a pat on the back!\n";
}
return 0;
}
Explanation:
there has to be semicolon after declaring score1,score2,score3; and 8 and 9 has to be in a single line.we should convert average variable to int because we are comparing with 100. and we should remove semi colon after if conditions.We should declare all the variables before we are using them. If we do not assign any value to them,randomly they will take any value as a default value.so by default perfect score variable is false.
code:
Note:If you have any queries...please comment...Thank you..
1 // This program averages 3 test scores. 2 // It uses the variable perfectScore as...
Find errors in code and get 100% feedback!! Foblem (30 Points) This program This programaverages > // It uses the ram has errors. Find the errors in the code: n averages 3 test scores. the variable perfect Score as a flag. Line # Line # include <iostream> using namespace std; int maino cout << "Enter your 3 test scores and I will ": <<"average them;": int score1, score2, score3, cin >> score1 >> score2 >> score3; double average; average (scorel...
This is what I have as of right now. I am lost on what to do next#include <stdio.h>#include <iostream>using namespace std;int main(){ double scores, numOfStudents, average = 0, highscore, sum = 0; string names; cout << "Hello, please enter the number of students" << endl; cin >> numOfStudents; do { cout << "Please enter the student's name:\n"; cin >> names; cout << "Please enter the student's...
#include<iostream> using namespace std; int main() { float num,avg,sum=0.0; int count=0; bool moreNumbers=true; cout<<"Enter grades:"<<endl; while(moreNumbers) { cin>>num; if(num < 0) { moreNumbers=false; } else { count = count+1; sum=sum+num; } } avg=sum/count; cout<<"Average grade:"<<avg<<endl; cout<<"How many grades were entered:"<<count<<endl; return 0; } Question: We need to add another loop to check input. Just like the input loop we already have, this one should use a boolean variable as a control. So, the logic could be something like this: Loop...
C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...
This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...
read in numbers into array , print out, sort - my program reads in and prints out but crashes before the sort - crashes after it prints out the scores - *important I have to use pointers!!!! c++ #include <iostream> using namespace std; void sortarray(int *tarray, int ); void displayarray(int *[], int); void averageshowarray(int *[], int); int main() { int Size; int count; cout << "enter the size: " << endl; cin >> Size; int...
3.14.1: String with digit. Set hasDigit to true if the 3-character passCode contains a digit. HELP ME FIX THIS #include <iostream> #include <string> #include <cctype> using namespace std; int main() { bool hasDigit; string passCode; hasDigit = false; cin >> passCode; for(int i=0;i<passCode.length();i++) { if(isdigit(passCode[i])) { hasDigit=true; break; } } if (hasDigit) { cout << "Has a digit." << endl; } else { cout << "Has no digit." << endl; } return 0; }
#include<iostream> using namespace std; double hey(int x){ if(x==2) return 1; int i=0; if (x%2==0){ while(i<=2){ cout<<(x/2)<<endl; i++; break; } } if (x%2==1){ while(i<=2){ i=3*x+1; cout<<i<<endl; } return 1; } } int main() { int n; cout<<"insert a number to check how many steps to reduce down to 2"<<endl; cin>>n; cout<<hey(n)<<endl; return 0; } I couldn't
c++, data structure Write a solution to test 2 problem 3 that uses selection sort to sort the items in the vector of integers. #include <iostream> #include <iterator> #include <string> #include <random> using namespace std; void insertionSort(int a[], int N) { int sorted = 0; for (int sorted = 0; sorted < N - 1; ++sorted) { int item_position = sorted + 1; int item = a[item_position]; while (item_position > 0 && a[item_position - 1] > item) { a[item_position] =...
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...