Pease.... I need help with this..Please aslo attach a successful screenshot and
ID: 3574060 • Letter: P
Question
Pease.... I need help with this..Please aslo attach a successful screenshot and comments.
C++
*******************************************************************************************
Mission:
fix me.cpp : Defines the entry point for the console application.
There are 5 error
FIX THEM, run the corrected code successfully.
comment the lines you fixed
#include "stdafx.h" // Visual Studios PC only
#include <iostream>
using namespace std;
#include "string"
int myFactorial( intt integer)
{
if( integer == 1)
return 1;
else
{
return (integer * (myFactorial(integer-1)));
}
}
int main() {
int j == 10;
string myName = "NoName";
cout << "Output sentence" << endl;
cout << 120 << endl;
cout << j << endl; // prints out the value of x
fi (( j == 0 ) || ( myName == "NoName" ))
{
cout << "J equals 0 OR myName equals NoName" << endl;
}
else
{
cout << "None are true" << endl;
}
for ( int i = 0; i < 5; i++)
{
cout << "Please enter an integer value: ";
cin >> j;
cout << "The value you entered is " << j;
cout << " and its double is " << i*2 << ". "; // print out double value
}
cout << "Enter your first and last name: ";
cin >> myName;
cout << "My first and last name is " << myName << endl;
cout << "The factorial of 15 is " << myFactorial(15)<< endl;
system("pause");
return 0;
}
Explanation / Answer
Hi,
I have fixed the errors. it is working as expected now and highlighted the code changes below.
#include <iostream>
using namespace std;
#include "string"
int myFactorial( int integer)
{
if( integer == 1)
return 1;
else
{
return (integer * (myFactorial(integer-1)));
}
}
int main() {
int j = 10;
string myName = "NoName";
cout << "Output sentence" << endl;
cout << 120 << endl;
cout << j << endl; // prints out the value of x
if (( j == 0 ) || ( myName == "NoName" ))
{
cout << "J equals 0 OR myName equals NoName" << endl;
}
else
{
cout << "None are true" << endl;
}
for ( int i = 0; i < 5; i++)
{
cout << "Please enter an integer value: ";
cin >> j;
cout << "The value you entered is " << j;
cout << " and its double is " << j*2 << ". "; // print out double value
}
cout << "Enter your first and last name: ";
cin >> myName;
cout << "My first and last name is " << myName << endl;
cout << "The factorial of 15 is " << myFactorial(15)<< endl;
// system("pause");
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Output sentence
120
10
J equals 0 OR myName equals NoName
Please enter an integer value: 10
The value you entered is 10 and its double is 20.
Please enter an integer value: 1
The value you entered is 1 and its double is 2.
Please enter an integer value: 2
The value you entered is 2 and its double is 4.
Please enter an integer value: 3
The value you entered is 3 and its double is 6.
Please enter an integer value: 4
The value you entered is 4 and its double is 8.
Enter your first and last name: Suresh
My first and last name is Suresh
The factorial of 15 is 2004310016
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.