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...
#include <iostream> uisng namespace std; int main() { cout<<"Enter your three test scores and I will "; <<" average them: "; int score1, score2, score3, cin>>score1>>score2>>score3; double average; average = (score1 + score2 + score3) / 3.0; if (average = 100); perfectScore = true; // set the flag variable cout<<"Your average is "<<average <<endl; bool perfectScore; if (perfectScore); { cout<<"Congratulations!\n"; cout<<"That's a perfect score.\n"; ...
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;...
previous assignment code /*C++ test program to test the classes, Animal, Mammal and Cat and print the results on console window.*/ //Main.cpp //include header files #include<iostream> //include Animal, Mammal and Cat header files #include "Animal.h" #include "Mammal.h" #include "Cat.h" using namespace std; int main() { //create Animal object Animal animal("Dog","Mammal",4); cout<<"Animal object details"<<endl; cout<<"Name: "<<animal.getName()<<endl; cout<<"Type: "<<animal.getType()<<endl; cout<<"# of Legs: "<<animal.getLegs()<<endl; cout<<endl<<endl; //create Cat object Cat cat("byssinian cat","carnivorous mammal",4,"short...
// This program will read in a group of test scores (positive integers from 1 to 100) // from the keyboard and then calculate and output the average score // as well as the highest and lowest score. There will be a maximum of 100 scores. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...
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[],...
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; }
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...