Concept explainers
Each of the following programs has errors. Find as many as you can.
58. // This
// It uses the variable perfectScore as a flag,
include <iostream>
using namespace std;
int main()
{
cout << "Enter your 3 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";
cout << "You deserve a pat on the back!\n";
return 0;
}
Learn your wayIncludes step-by-step video
Chapter 4 Solutions
STARTING OUT WITH C++FROM CONTROL STRU
Additional Engineering Textbook Solutions
Artificial Intelligence: A Modern Approach
Starting Out with Python (4th Edition)
Java How To Program (Early Objects)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Concepts Of Programming Languages
- Personal BestWrite a program that asks for the name of a pole vaulter and the dates and vaultheights (in meters) of the athlete’s three best vaults. It should then report, in order ofheight (best first), the date on which each vault was made and its height.Input Validation: Only accept values between 2.0 and 5.0 for the heights.arrow_forwardchange normal body temperature to 36.5–37.5 °C #include<iostream>using namespace std;int main(){ float temp;cout<<"Enter the body temperature in Celsius\n";cin>>temp;if (temp>=37){cout<<"The quarantine of the patient is required\n";cout<<"Enter the name of the patient\n";string patient;cin>>patient;cout<<"Where the passenger is from\n";string place;cin>>place;cout<<patient<<" from "<<place<<"is to be quarantined at Hospital"; }cout<<"Normal temperature\n";}arrow_forward10. Each code example is incorrect. Indicate why! (2 errors each) 1. if (i=0)// //...code 2. for(;;)// //...code 3. public static void SquareIt(int a){// return a*a; } 4. while(1);// //...codearrow_forward
- #include using namespace std; int main() { int type; double Vth, Vg, Vd, Vs; cin>>type>>Vth>>Vg>>Vd>>Vs; return 0; }arrow_forwardTwin primes are a pair of prime numbers that differ by 2. Forexample, 3 and 5 are twin primes, 5 and 7 are twin primes, and 11 and 13 aretwin primes. Write a program to find all twin primes less than 1,200. Display theoutput as follows:(3, 5)(5, 7)...arrow_forwardWhat will the following program display? #include using namespace std; int main() { int unus, duo, tres; unus = duo = tres = 5; unus += 4; duo *= 2; tres −= 4; unus /= 3; duo += tres; cout << unus << endl; cout << duo << endl; cout << tres << endl; return 0; }arrow_forward
- 1. [LO 1, LO 2, LO 3 & LO 4, Treasure Hunter Description You are in front of a cave that has treasures. The cave can be represented in a grid which has rows numbered from 1 to , and columns numbered from 1 to . For this problem, define (x,y ) as a tile that is in the the-x row and the y-row. There is a character in each tile, which indicates the type of that tile. Tiles can be floors, walls, or treasures which are represented respectively by the characters '.' (period), '#' (hashmark), and '*' (asterisk). You can go through the floor tiles and treasures, but you can't get past the wall tiles.Initially, you are in a tile (??, Sy). You want to visit all the treasure squares, and retrieve the treasure. When you visit a treasure tile, the treasure is instantly retrieved, and the tile turns into a floor.In a move, if you are on a tile (?,y), then you can move to the right tile above (?-1,y), right (?,y + 1), down (? + 1, ), and left (?, 1) of the current tile. The tile you visit must…arrow_forwardIdentify and correct the error int main(void) { double x = 12.8 double y Follow the code.arrow_forwardT/F 7. You can use, >, ==,!=, =, >= to match int, float, and double variables, but you must use compareTo(), equals(), and equalsIgnoreCase to compare char and String variables ().arrow_forward
- Coin Converter Lab Description Write a program that asks the user to enter an amount of money in the format of dollars and remaining cents. The program should calculate and print the minimum number of coins (quarters, dimes, nickels and pennies) that are equivalent to the given amount.Hint: In order to find the minimum number of coins, first find the maximum number of quarters that fit in the given amount of money, then find the maximum number of dimes that fit in the remaining amount, and so on. File Name coins.py Score There are five tests each worth 2 points For example, an execution should look like this:Please enter the amount of money to convert:# of dollars: 2# of cents: 37The coins are 9 quarters, 1 dimes, 0 nickels and 2 pennies python labsarrow_forward// SuperMarket.cpp - This program creates a report that lists weekly hours worked // by employees of a supermarket. The report lists total hours for // each day of one week. // Input: Interactive // Output: Report. #include <iostream> #include <string> using namespace std; int main() { // Declare variables. const string HEAD1 = "WEEKLY HOURS WORKED"; const string DAY_FOOTER = " Day Total "; // Leading spaces in DAY_FOOTER are intentional. const string SENTINEL = "done"; // Named constant for sentinel value. double hoursWorked = 0; // Current record hours. string dayOfWeek; // Current record day of week. double hoursTotal = 0; // Hours total for a day. string prevDay = ""; // Previous day of week. bool notDone = true; // loop control // Print two blank lines. cout << endl << endl; //…arrow_forwardA Millenial is someone born between 1981 and 1996 (inclusive). Using boundary analysis write test cases to test the IsMillenial function: public bool IsMillenial(int year) that takes a year of birth (in the Gregorian Calendar) and returns true if the person is a millenial and false if it isn't. If the year is not a valid Gregorian Calendar year then the function throws ArgumentOutOfRangeException. Note: There is total of 13 test cases. using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; [TestClass] public partial class { // Your code starts here // Your code ends here }arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning