473,385 Members | 1,347 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,385 software developers and data experts.

c++ that reads height and weight and print shapes

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7.  
  8. {
  9.     int ans, num, a, b, c, d;
  10.     int h = 0;
  11.     int w = 0;
  12.     char ans2;
  13.  
  14.     cout << "[1] Math algorithms " << endl;
  15.     cout << "[2] Figures " << endl;
  16.     cout << "[3] Exit " << endl;
  17.     cout << "Enter your choice. ";
  18.         cin >> ans;
  19.     cout << endl;
  20.  
  21.     if (ans == '2') {
  22.         cout << endl;
  23.         cout << " [a] Print a Rectangle " << endl;
  24.         cout << " [b] Print a Triangle " << endl;
  25.         cout << " [c] Print a Rectangle Outline " << endl;
  26.         cout << " Enter your choice. ";
  27.             cin >> ans2;
  28.  
  29.             if (ans2 == 'a') {
  30.                 cout << endl;
  31.                 cout << " Print a Rectangle" << endl;
  32.                 cout << "  Enter Height. ";
  33.                     cin >> h;
  34.                 cout << "    Enter Width. ";
  35.                     cin >> w;
  36.                     {
  37.                         for (c=1; c<=h; c++)
  38.                         {
  39.                             for (d=1; d<=w; d++)
  40.                             {
  41.                                 cout << "*";
  42.                             }
  43.                                     cout << endl;
  44.                         }
  45.                 }
  46.  
  47.                 else if (ans2 == 'b') 
  48.                 cout << endl;
  49.                 cout << "   Print a Triangle" << endl;
  50.                 cout << "    Enter a Number. ";
  51.                     cin >> num;
  52.                 for (a = 1; a <= num; a++)
  53.                 {
  54.                     for (b = 1; b <= a; b++)
  55.                     {
  56.                         cout << "*";
  57.                     }
  58.  
  59.                     cout << endl;
  60.  
  61.                 }
  62.         }
  63.     }
  64.  
  65.         cout << endl;
  66.  
  67.     return 0;
  68. }
  69.  
  70.  


//please help, i am encountering syntax error which says "illegal else without matching if"
May 16 '11 #1
2 2530
whodgson
542 512MB
It may be a lack of curly brackets after l 47
May 16 '11 #2
Banfa
9,065 Expert Mod 8TB
Actually I think it is the random { at line 36, there is no syntactical problem with line 47 but the { at 36 means the } at 45 closes this rather than the { (for the if) at 29.

Because of this you are still inside the if code block when you try the else statement so there is no if to attach it to.
May 16 '11 #3

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

Similar topics

5
by: Bill Short | last post by:
I have a subreport in the detil section of my main report. The subreport can grow. I have a vertical line that fills the rest of the section. As you can probably guess I need to change the top...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
1
by: Mike Collins | last post by:
I am trying to create some pages and have them take 100% of the window, but I cannot get 100% to work. If I set the height of my div, the page displays a scroll bar and it looks like I set the...
1
by: Nate12o6 | last post by:
Hey guys, i am having trouble with getting the heights corrected on my fieldset. Right now i have 2 table cells side by side. And inside of each there is a field set. The fieldset to the right...
6
by: dr3amxstar | last post by:
Hi Im using VB express 2005 I encountered some problems while drawing shapes in visual basic. Whenever i print shape on the picturebox it appears, but when i minimize it or go to another form and...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
2
by: ssmeshack | last post by:
Hai all, Im having problem to set minimum height to <td> tag. It only takes height only not min-height. Im ie7 browser and developing web based system in Visual Web Deveploper 2008 (C# .Net). ...
2
by: dmorand | last post by:
When I try to print a 'print version' of my page it looks fine in IE 7, but when I print in IE 6 the margins are all screwed up. The page itself looks the same in both browsers, it's just when I...
2
by: ziycon | last post by:
I have the below code, when a user clicks on the <a href="#" onclick="showhide('languages'); return false;">Language(<div id="current_lang">en</div>)</a> it shows a DIV that is hidden and when...
6
by: Fuugie | last post by:
I am having trouble trying to figure out a way to convert the feet to inches and have this still work. i have ran into a brick wall pretty much and could use all the help i could get. The correct...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.