Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

im not getting what im doing wrong, coding for c++

 

Write a program whose inputs are three integers, and whose output is the smallest of the three values.

Ex: If the input is:

7 15 3

the output is:

3

#include <iostream>
using namespace std;

int main() {
   
   int a = 3, b = 15, c = 7;
   
   cout << a << b << c;
   cin >> 3 >> 15 >> 7;   //a = 3, b = 15, c = 7
   
   if (a <  b && a < c)
      cout << " a " << 3; 
       
   }
   
   else if (b > a && b < c)
      cout << " b " << 7;
        
   }
   
   else (c < a && c < b)
      cout << " c " << 15;
      
   }
   
   
     
   return 0;
}

 

 

Expert Solution
Check Mark
Step 1: Errors in the given Code

There are several issues with your code. I'll correct them step by step:

  1. You should remove the initial assignments to a, b, and c because you want to take user inputs for these values.
  2. You should use appropriate variables in your if conditions.
  3. You need to use && for the conditions properly.
  4. You should remove unnecessary numbers from the cin statement.
Still need help?
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

this is the error im getting now 

 

main.cpp:16:4: error: expected unqualified-id before ‘else’
   16 |    else if (b <= a && b <= c)
      |    ^~~~
main.cpp:19:4: error: expected declaration before ‘}’ token
   19 |    }
      |    ^
main.cpp:21:4: error: expected unqualified-id before ‘else’
   21 |    else {
      |    ^~~~
main.cpp:27:4: error: expected unqualified-id before ‘return’
   27 |    return 0;
      |    ^~~~~~
main.cpp:28:1: error: expected declaration before ‘}’ token
   28 | }
      | ^

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

this is the error im getting now 

 

main.cpp:16:4: error: expected unqualified-id before ‘else’
   16 |    else if (b <= a && b <= c)
      |    ^~~~
main.cpp:19:4: error: expected declaration before ‘}’ token
   19 |    }
      |    ^
main.cpp:21:4: error: expected unqualified-id before ‘else’
   21 |    else {
      |    ^~~~
main.cpp:27:4: error: expected unqualified-id before ‘return’
   27 |    return 0;
      |    ^~~~~~
main.cpp:28:1: error: expected declaration before ‘}’ token
   28 | }
      | ^

Solution
Bartleby Expert
by Bartleby Expert
SEE SOLUTION
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education