Question

There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark...

There are 7 syntax errors and 3 semantic errors in the following code segment. Please mark them in the code and explain the reason briefly in place.

#include<iostream>

using namespace std;

int main()

{

cout<<”Please input the radius (in integer): ”>>endl;

int 1var = 10, var=20;

double area = 40;

cin<< var; //get an input of the radius and store in var

float continue;

float const pi = 2.64;

pi += 0.5;

do

{

cout<<”The radius is ”<<”var”<<endl; //print the value of var to console

}while(var <0) //wanted to make sure that user input (var) >=0

area = pi*var; //variable area should store the area of the circle with radius var

return 0;

Homework Answers

Answer #1

#include<iostream>
using namespace std;
int main(){

// ERROR 1: we should use << not >>
cout<<”Please input the radius (in integer): ”<<endl;

//ERROR 2: variale name can't start with digit
int var1 = 10, var=20;

double area = 40;
//ERROR 3
// we use >> to get input
cin>> var; //get an input of the radius and store in var

// ERROR 4: we can't use keywords as variale names
float continue;

float const pi = 2.64;
//ERROR 5: we can't change the value of const
pi += 0.5;

do
{

// ERROR: we shoud not use "" to print variable data
cout<<”The radius is ”<<”var”<<endl; //print the value of var to console
var++; // ERROR 7: here we should change the value otherwise it will be infinite loop
}while(var <0) // ERROR 6: ; semicolon missed
//wanted to make sure that user input (var) >=0

area = pi*var; //variable area should store the area of the circle with radius var

return 0;

Know the answer?
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
Similar Questions
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment...
C++ please Write code to implement the Karatsuba multiplication algorithm in the file linked in Assignment 2 (karatsuba.cpp) in Canvas (please do not rename file or use cout/cin statements in your solution). As a reminder, the algorithm uses recursion to produce the results, so make sure you implement it as a recursive function. Please develop your code in small The test program (karatsuba_test.cpp) is also given. PLEASE DO NOT MODIFY THE TEST FILE. KARATSUBA.CPP /* Karatsuba multiplication */ #include <iostream>...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
C++ question. Please explain the code and how it resulted in the output. Explain each line...
C++ question. Please explain the code and how it resulted in the output. Explain each line along with the aspects of "buffers" if possible. Everything is listed below. Code below: #include <iostream> #include <string> using namespace std; int main() {    cout << boolalpha;    cout << static_cast<bool>(1) << endl;    cout << static_cast<bool>(0) << endl;    string s = "AAARGH!!!";    if (s.find("AAA")) { cout << 1 << endl; }    if (s.find("RGH")) { cout << 2 << endl;...
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Please fill in the blank bolded below that would be the best choice for this program....
Please fill in the blank bolded below that would be the best choice for this program. #include <iostream> using namespace std; const int size = 100000; class TheBig { public: double operator[](int index) const {return (theData[index]);} private: double theData[size]; }; void firstToBeThe( ______________________________________________________) { for (int i = 0; i <size; i++) cout << value[i] <<endl; } int main() { TheBig one; firstToBeThe(one); }
No matter what I do I cannot get this code to compile. I am using Visual...
No matter what I do I cannot get this code to compile. I am using Visual Studio 2015. Please help me because I must be doing something wrong. Here is the code just get it to compile please. Please provide a screenshot of the compiled code because I keep getting responses with just code and it still has errors when I copy it into VS 2015: #include <iostream> #include <conio.h> #include <stdio.h> #include <vector> using namespace std; class addressbook {...
When the user enters 2 the following program segment should print the message “You’ve selected to...
When the user enters 2 the following program segment should print the message “You’ve selected to get an A”, however it always prints “You’ve selected to get a C”. Rewrite the code segment to behave properly, i.e., print the proper message: int selection; cout << “Please enter the grade you would like to receive “ << endl; cout << “1 = C, 2 = A”; cin >> selection; if (selection = 1) cout << “You’ve selected to get a C“...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is...
Menu.cpp isn't working. C++  utilize inheritance to create a banking app. The architecture of the app is up to you as long as you implement some form of inheritance. Below is my code however the credit and the actual menu isn't working. Can i get some help on getting the menu to work properly. // BankAccount.h #ifndef ACCOUNT_H #define ACCOUNT_H #include <string> #include <iostream> using namespace std; class BankAccount { protected : int noOfWithdrawls; private: // Declaring variables    float balance;...