Question

In: Computer Science

C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...

C++ code Why my code is not compiling? :(

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

const int CWIDTH = 26;

int main()

{

   int choice;

   double convertFoC, converCtoF;

   double starting, endvalue, incrementvalue;

   const int CWIDTH = 13;


   do {

      cin >> choice;

   switch (choice)

   {

   

   cin >> starting;

   if (starting == 28){

      cout << "Invalid range. Try again.";

   }

   while (!(cin >> starting)){

      string  garbage;

      cin.clear();

      getline(cin, garbage);

      cout << "Invalid data Type, must be a number. Program terminated." << endl;

      return 0;


   }

   

   cin >> endvalue;

   cin >> incrementvalue;

   switch (choice) {

   case 1:

      cout << "Fahrenheit" << setw(17) << "Celsius" << endl;

      for (double calcCelsius = starting; calcCelsius <= endvalue; calcCelsius = calcCelsius + incrementvalue)

      {

         convertFoC = (5.0 / 9.0) * (calcCelsius - 32.0);

         cout << showpoint << fixed << setprecision(2) << calcCelsius <<  setprecision(2) << setw(21) << convertFoC << right;

         cout << endl;

      }

      break;

   case 2:

      cout << "Celsius" << setw(CWIDTH) << "Fahrenheit\n";

      for (double calcFahrenheit = starting; calcFahrenheit <= endvalue; calcFahrenheit = calcFahrenheit + incrementvalue)

      {

         converCtoF = ((9.0 / 5.0) * calcFahrenheit) + 32.0;

         cout << setw(CWIDTH) << showpoint << fixed << setprecision(1) << calcFahrenheit << fixed << setprecision(1) << setw(CWIDTH) << converCtoF << right;

         cout << endl;

      }

   case 3:

      cout << " thank you";

      break;

   } while (choice !=3);

   

   return 0;

   

}

Solutions

Expert Solution

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

const int CWIDTH = 26;

int main()

{

    int choice;

    double convertFoC, converCtoF;

    double starting, endvalue, incrementvalue;

    const int CWIDTH = 13;

    do

    {

        cin >> choice;

        cin >> starting;

        if (starting == 28)

        {

            cout << "Invalid range. Try again.";

            continue;

        }

        cin >> endvalue;

        cin >> incrementvalue;

        switch (choice)

        {

        case 1:

            cout << "Fahrenheit" << setw(17) << "Celsius" << endl;

            for (double calcCelsius = starting; calcCelsius <= endvalue; calcCelsius = calcCelsius + incrementvalue)

            {

                convertFoC = (5.0 / 9.0) * (calcCelsius - 32.0);

                cout << showpoint << fixed << setprecision(2) << calcCelsius << setprecision(2) << setw(21) << convertFoC << right;

                cout << endl;

            }

            break;

        case 2:

            cout << "Celsius" << setw(CWIDTH) << "Fahrenheit\n";

            for (double calcFahrenheit = starting; calcFahrenheit <= endvalue; calcFahrenheit = calcFahrenheit + incrementvalue)

            {

                converCtoF = ((9.0 / 5.0) * calcFahrenheit) + 32.0;

                cout << setw(CWIDTH) << showpoint << fixed << setprecision(1) << calcFahrenheit << fixed << setprecision(1) << setw(CWIDTH) << converCtoF << right;

                cout << endl;

            }

            break;

        case 3:

            cout << " thank you";

            break;

        }

    } while (choice != 3);

    return 0;

}

.

Output:

.


Related Solutions

What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std;...
What is the flowchart for this code. Thank You! #include<iostream> #include<iomanip> #include<string> #include<cmath> using namespace std; float series(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum += r[i];    return sum; } float parallel(float r[], int n) {    float sum = 0;    int i;    for (i = 0; i < n; i++)        sum = sum + (1 / r[i]);...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip>...
Add Bubble Sorting & Binary Search Functions to the following code (C++) #include<iostream> #include<fstream> #include<string> #include<iomanip> #include<algorithm> using namespace std; const int row = 10; const int col = 7;   ifstream name; ifstream grade; ofstream out; void readData(string stname[row], int stgrade[row][col]); void stsum(int stgrade[row][col], int total[row]); void staverage(int total[row], double average[row]); void stlettergrade(double average[row],char ltrgrade[row]); void displayData(string stname[row], int stgrade[row][col], int total[row], double staverage[row], char ltrgrade[row]); void swapltrgrade(char* xp, char* yp); int main() {    int STG[row][col] = { {0},{0}...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using...
C++ CODE ONLY Using the following code. #include <iostream> #include <string> #include <climits> #include <algorithm> using namespace std; // M x N matrix #define M 5 #define N 5 // Naive recursive function to find the minimum cost to reach // cell (m, n) from cell (0, 0) int findMinCost(int cost[M][N], int m, int n) {    // base case    if (n == 0 || m == 0)        return INT_MAX;    // if we're at first cell...
Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function...
Can someone covert the code into C language #include<iostream> #include<iomanip> #include<ios> using namespace std; /******************************************************************************** Function name: main Purpose:                   main function In parameters: b,r,i Out paramters: trun,error,total,value Version:                   1.0 Author: ********************************************************************************/ void main() {    int i;//declaring this variable to get value for quitting or calaculating series    do {//do while loop to calaculate series until user quits        cout << "Enter 1 to evaluate the series." << endl;       ...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace...
C++ finish the AVL Tree code: #include "AVLNode.h" #include "AVLTree.h" #include <iostream> #include <string> using namespace std; AVLTree::AVLTree() { root = NULL; } AVLTree::~AVLTree() { delete root; root = NULL; } // insert finds a position for x in the tree and places it there, rebalancing // as necessary. void AVLTree::insert(const string& x) { // YOUR IMPLEMENTATION GOES HERE } // remove finds x's position in the tree and removes it, rebalancing as // necessary. void AVLTree::remove(const string& x) {...
For C++ Consider the following code defining classes for assets and office equipment: #include<string> #include<iostream> using...
For C++ Consider the following code defining classes for assets and office equipment: #include<string> #include<iostream> using namespace std; // class definition for asset class Asset{ protected: int value; // value of asset in cents public: Asset(int value); // constructor int get_value(); // get the value }; Asset::Asset(int val){ // implementation of constructor value=val; } int Asset::get_value(){ // implementation of get_value return value; } // abstract class for office equipment class OfficeEquipment:public Asset{ public: OfficeEquipment(int val); // constructor virtual void use_item()...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left;...
#include "IntVariableTable.h" #include "Tokens.h" #include <assert.h> #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::left; using std::right; using std::setw; using std::string; // The IntVariableTable constructor dynamically allocates the fixed size array of integer variables. IntVariableTable::IntVariableTable() { int_variable_table = new IntVariableEntry[MAX_INT_VARIABLES]; } // The IntVariableTable destructor deallocates the integer variable array. IntVariableTable::~IntVariableTable() { delete[] int_variable_table; } // Returns the number of variables added to the integer variable table. int IntVariableTable::numVariables() const { return num_int_variables; } // Returns the index of...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using...
A C++ question: I want to indent the code of this C++ program: #include<iostream> #include<cstring> using namespace std; int lastIndexOf(char *s, char target) { int n=strlen(s); for(int i=n-1;i>=0;i--) { if(s[i]==target) { return i; } } return -1; } void reverse(char *s) { int n=strlen(s); int i=0,j=n-1; while(i<=j) { char temp=s[i]; s[i]=s[j]; s[j]=temp; i++; j--; } return; } int replace(char *s, char target, char replacementChar) { int len=strlen(s); int total=0; for(int i=0;i<len;i++) { if(s[i]==target) { s[i]=replacementChar; total+=1; } } return total;...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count =...
#include <iostream> #include <iomanip> using namespace std; int main() {     int studentid, numberreverse[20], count = 0, maximum = 0, minimum = 0;     cout << "Enter your student ID number: ";     cin >> studentid;     cout << "Student ID Number = " << studentid << endl;     while (studentid != 0)     {          numberreverse[count] = studentid % 10;          if (count == 0)          {              minimum = numberreverse[count];              maximum = minimum;          }          else...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT