Question

Part II: Programming Errors Fix the Errors in C++ Segments of Code and C++ Programs (10...

Part II: Programming Errors Fix the Errors in C++ Segments of Code and C++ Programs (10 Marks) 1. Find the error(s) in the following program segment and correct them.

int b[10] = [0];

for (int i=0; i <= 10, i++)

b[i] = 2*i+3;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int b[10] = [0]; //error in [0]..we cant assign value like this...correct one is int b[10] = {0};

for (int i=0; i <= 10, i++) //here there is no termination after condition check i <= 10,..remove comma from here and put semicon;

b[i] = 2*i+3;

//Correct code:

#include<iostream>
using namespace std;

int main()
{
int b[10] = {0};
for (int i=0; i<10; i++)
b[i] = 2*i+3;
cout<<endl;
}

Add a comment
Know the answer?
Add Answer to:
Part II: Programming Errors Fix the Errors in C++ Segments of Code and C++ Programs (10...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Fix the errors in the following code. (Not all errors are syntax related) #include <iostream>...

    C++ Fix the errors in the following code. (Not all errors are syntax related) #include <iostream> using namespace std; int main() { //Part A int numA numA = 10; cout << numA << end; /* Part B */*/ int numB = numA; cin >> usrInput; int usrInput = 0; numB = numB + usrInput; cout << numB <"/n";    /* Part C */ int numC = 10000000000; cout << numC << endl; return 0; }

  • c++ What is wrong with the following code segment? Fix the error and explain why its...

    c++ What is wrong with the following code segment? Fix the error and explain why its wrong. int* m[3]; for(int i = 0; i < 3; i++) m[i] = new int[4]; delete [] m;

  • C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code...

    C++ class 3.2.4: If-else statement: Fix errors. Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) cout << "Positive." << endl; else cout << "Not positive, converting to 1." << endl; Answer #include using namespace std; int main() { int userNum; cin >> userNum; /* Your solution goes here */ return 0; userNum = 1; cout << "Final: " << userNum << endl;

  • 12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude...

    12) 8 pts. Find the errors in the following code fragment and correct them. #i nclude <iostream> using namespace std; double fudge (double s) f return s 2.3; int mainO cout >> "Your original estimate" double estimate; cin >> estimate; cout << endl; for (int 1 = 0;1c3;i++); cout << "EStimate' < fudge(estimate) <<endl Hint: There are 4 syntax errors. There is one error that is syntactically correct but causes the output to not be what you would expect. Once...

  • Find and fix the errors in this C++ code: * This program illustrates a variety of...

    Find and fix the errors in this C++ code: * This program illustrates a variety of common loop errors. * Fix the errors in each section. */ #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; // SECTION I: update comment below on how you fixed this section's code, and tests run // FIX = // TESTS: cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout <<...

  • C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix...

    C# Programming: DebugNine2 The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. +DebugNine2.cs Instructions Build Output The provided file has syntax and/or logical errors. Determine the problem(s) and fix the program. 1/ Creates a Breakfast class 2 // and instantiates an object 3// Displays Breakfast special information 4 using static System.Console; Conpilation fatled: 2 error(s), 8 warnings DebugNine2.cs(9,61): error C$1810: Newline in constant DebugNine2.cs (11,6): error CS1525: Unexpected synbol "Writeltne class DebugNine2 7static void...

  • Part III. Common String Errors The following two example programs demonstrate common errors that often occur...

    Part III. Common String Errors The following two example programs demonstrate common errors that often occur when programming with Strings. public class StringErrors1 {     public static void main(String [] args) {       String greeting = "hello world";       greeting.toUpperCase();       System.out.println(greeting);     } } Type above code in Dr. Java or Eclipse. Compile and run the program a few times. What does this program do? How might you make the program more user-friendly? Now run the program two more...

  • Debugging: The code below has six errors. The errors may be syntax errors or logic errors,...

    Debugging: The code below has six errors. The errors may be syntax errors or logic errors, and there may be more than one per line; examine the code carefully to find them. Indicate each of the errors you find by writing the line number and correction in the space provided below. This program is designed to take a constant number of scores (3 in this case) and store them into an array. Then the array is passed to a function...

  • /* •   The following code consists of 5 parts. •   Find the errors for each part...

    /* •   The following code consists of 5 parts. •   Find the errors for each part and fix them. •   Explain the errors using comments on top of each part. */ #include <stdio.h> #include <string.h> int main( ) { ////////////////////////////////////////////////////////////////////////// //////////////        Part A. (5 points)                ////////////////// int g(void) { printf("%s", Inside function g\ n " ); int h(void) {       printf(" % s ", Inside function h\ n "); } } printf("Part A: \n "); g(); printf(" \n"); ////////////////////////////////////////////////////////////////////////// //////////////       ...

  • Describe all of the errors in this c program and then fix them. (note whether they...

    Describe all of the errors in this c program and then fix them. (note whether they are syntactical or sematic) include studio.h int main(void} /* this prints the number of weeks in a year int s s := 56; print (There are s weeks in a year.); return 0;

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT