473,378 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

help needed in C++ with the if-else-if ladder.

I need help with the if else if ladder.
Here is my problem:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int lyle, dunn, charles, name;
  7.  
  8.     cout << "enter name:\n";
  9.     cin >> name;
  10.  
  11.  
  12.         if(name == 1) cout << "enter dunn:\n";
  13.         cin >> dunn;
  14.         cout << dunn * 2;
  15.         else if(name == 2) cout << "enter lyle:\n";
  16.         cin >> lyle;
  17.         cout << lyle * 2;
  18.  
  19.  
  20.     cin.get();
  21.     cin.get();
  22.     return 0;
  23.  
I never got to finish the if else if ladder, because my compiler already gives an
incorrect syntax.
Apr 13 '10 #1
3 2579
RedSon
5,000 Expert 4TB
if else if syntax for c++ is:

Expand|Select|Wrap|Line Numbers
  1. if (condition)
  2. {
  3.   //execute this code
  4. }
  5. else if (condition)
  6. {
  7.   //exectue this code
  8. }
  9. else
  10. {
  11.  //execute this code
  12. }
Apr 13 '10 #2
jkmyoung
2,057 Expert 2GB
Yes, you're missing the braces around the clauses:
{ and }

The compiler can't tell how to compile it otherwise.
Apr 13 '10 #3
@RedSon
thanks a lot
Apr 14 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jack Smith | last post by:
Help needed on this question. Any help is appreciated. Thanks in advance. Given a binary string (i.e. a finite sequence of 0's and 1's) we choose any two digit substring 01 and replace it by a...
10
by: eLisHa | last post by:
i have an arraylist that gets it's values dynamiclly from the database, after paging, searching & more in the ASP.net file. What im trying to do, is sort the results that are sorted in the...
1
by: Proteus | last post by:
Any help appreciated on a small perl project I need to write for educator/teaching purposes. I have not programmed perl for some time, need to get up to speed, maybe some kind souls hrere will help...
1
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a...
7
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One...
1
by: Robert Rota | last post by:
Hello, Please help me with the following struct development: I need three levels of a data structure simulating a 3 level pagetable. I need a structure which has a pointer to an array of...
2
by: MichaelH | last post by:
Hi all, I am writing a program that has to draw musical notes on a staff. To do this I need to draw Ellispses (representing the notes) on a horizontal line and rotate them slightly (by 15...
4
by: perryschon | last post by:
Can someone please help me out with the Visual Basic source code needed that allows configuration and usage of comm ports in any PC? I am constructing an asynchronous serial communication RS-232...
2
by: mia23 | last post by:
Hello, I am a java beginner and I need series help in solving this program; my assignment is due after 2 days and I can't understand this program . This is THE PROGRAM:  The ABC medical clinic...
1
by: Joel Fireman | last post by:
Help Needed: Upgrade Fedora 4 / Apache 2 to PHP 5.2.x from 5.0.4 I've been testing Joomla as a content manager for the County offices, and it looks pretty good. Unfortunately, I decided to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.