Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So I have this problem pretty much right, except that white space, highlighted i

ID: 3858822 • Letter: S

Question

So I have this problem pretty much right, except that white space, highlighted in yellow. I don't know what I added to get that, but I need to get rid of that to get the answer right. I have posted my code below. Only get rid of rthe white space. DO NOT change anything else for this answer is correct besides the whitespase issue.

Thanks!

***************

#include <iostream>
#include <string>

using namespace std;

//Function that calculates square root of a function
float squareRoot(float num)
{
float result;
int i;

//Return 0 if num is 0
if (num == 0)
return 0;

//Calculating half the number
result = num/2.0;

//Iterate and accumulate the result for calculating square root of a function
for(i=1; i<=10; i++)
result = (result + (num/result))/2.0;

//Returning result
return result;
}

//Function that calculates square of a function
float square(float num)
{
//Returning square value
return num * num;
}

//Main function
int main()
{
float sideA, sideB, sideC;

string tryAgain = "yes";

//Loop till user wants to stop
while(tryAgain == "yes")
{
//Reading first side
cout << " Enter side A: ";
cin >> sideA;
cout << sideA;

//Reading second side
cout << " Enter side B: ";
cin >> sideB;
cout << sideB;

//Calculating third side
sideC = squareRoot( square(sideA) + square(sideB) );

//Printing result
cout << " Side C is " << sideC;

cin.ignore();

//Reading user choice
cout << " Continue? ";
cin>>tryAgain;
cout<<tryAgain;


cout << " ";
}
return 0;
}

Latest submission 11:31 AM on 07/20/17 1: Compare output Output is nearly correct; but whitespace differs. See highlights below 3 yes Input no Enter side A: 3 Enter side B: 4 Side C is 5 Continue? yes Enter side A: 33 Enter side B: 44 Side C is 55 Continue? no Your output Enter side A: 3 Enter side B: 4 Side Cis!5 Continue? yes Enter side A: 33 Enter side B: 44 Side C is 55 Continue? no Expected output

Explanation / Answer

You added space after

program:

#include <iostream>
#include <string>
using namespace std;
//Function that calculates square root of a function
float squareRoot(float num)
{
float result;
int i;
//Return 0 if num is 0
if (num == 0)
return 0;
//Calculating half the number
result = num/2.0;
//Iterate and accumulate the result for calculating square root of a function
for(i=1; i<=10; i++)
result = (result + (num/result))/2.0;
//Returning result
return result;
}
//Function that calculates square of a function
float square(float num)
{
//Returning square value
return num * num;
}
//Main function
int main()
{
float sideA, sideB, sideC;
string tryAgain = "yes";
//Loop till user wants to stop
while(tryAgain == "yes")
{
//Reading first side
cout << "Enter side A: "; //Space removed
cin >> sideA;
cout << sideA;
//Reading second side
cout << " Enter side B: "; //Space removed
cin >> sideB;
cout << sideB;
//Calculating third side
sideC = squareRoot( square(sideA) + square(sideB) );
//Printing result
cout << " Side C is " << sideC; //Space removed
cin.ignore();
//Reading user choice
cout << " Continue? "; //Space removed
cin>>tryAgain;
cout<<tryAgain;

cout << " ";
}
return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                       

sh-.2$ main                                                                                                                                                                    

Enter side A: 3

3                                                                                                                                                                               

Enter side B: 4 4   

Side C is 5                                                                                                                                                                     

Continue? yes yes   

Enter side A: 33

33                                                                                                                                                                              

Enter side B: 44 44

Side C is 55                                                                                                                                                                    

Continue? no no

sh-4.2$                                                                                                                                                                         

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote