LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 10-10-2010, 06:27 PM   #1
boilers969
Member
 
Registered: Oct 2010
Posts: 55

Rep: Reputation: 0
What is wrong with this C program?


Here is my program. I've been working on it for over 20 hours and am really frustrated. It asks the user for input and then prints a shape of a certain length. The errors I get when I compile are:

shape.c: In function âmainâ:
shape.c:22: error: expected identifier or â(â before âintâ
shape.c:58: error: expected expression before âreturnâ
shape.c:59: error: expected expression before â}â token
shape.c:59: error: expected expression before â}â token

Please help! Thank you!

Code:
#include<stdio.h>

int main()
{
while(1>0){
char shape;
char s,h,f;
shape='s';
shape='h';
shape='f';
int row;
printf("Enter shape type (s/h/f):");
scanf("%c",&shape);
printf("Enter shape length: ");
scanf("%d",&row);
if(row<=0)
printf("Shape length cannot be negative. Try again\n");
}
for(int s=1,int h=2,int f=3){
switch(s,h,f)
{
case 1:
{int i,row;
for(i=row;i>=1;i--)
printf("*\n");
break;}
case 2:
{int i,j,k,row,m;
m=row;
for(i=1 ; i<=m; i++)
{
for (j=1 ; j>=row; j--)
printf(" ");
{for(k=1; k<=i; k=k+1)
printf("*");
printf("\n");}}
break;}
case 3:
{int i,j,k,row,m;
m=row;
for(i=0;i<m;i++)
{
printf("\n");
for(k=0;k<row;k++)
printf(" ");
for(j=0;j<=i;j++)
printf(" *");
row--;
}
printf("\n");
break;}
default:
break;
}}
return(0);
}
 
Old 10-10-2010, 06:40 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by boilers969 View Post
Here is my program. I've been working on it for over 20 hours and am really frustrated. It asks the user for input and then prints a shape of a certain length. The errors I get when I compile are:

shape.c: In function âmainâ:
shape.c:22: error: expected identifier or â(â before âintâ
shape.c:58: error: expected expression before âreturnâ
shape.c:59: error: expected expression before â}â token
shape.c:59: error: expected expression before â}â token

Please help! Thank you!

Code:
#include<stdio.h>

int main()
{
while(1>0){
char shape;
char s,h,f;
shape='s';
shape='h';
shape='f';
int row;
printf("Enter shape type (s/h/f):");
scanf("%c",&shape);
printf("Enter shape length: ");
scanf("%d",&row);
if(row<=0)
printf("Shape length cannot be negative. Try again\n");
}
for(int s=1,int h=2,int f=3){
switch(s,h,f)
{
case 1:
{int i,row;
for(i=row;i>=1;i--)
printf("*\n");
break;}
case 2:
{int i,j,k,row,m;
m=row;
for(i=1 ; i<=m; i++)
{
for (j=1 ; j>=row; j--)
printf(" ");
{for(k=1; k<=i; k=k+1)
printf("*");
printf("\n");}}
break;}
case 3:
{int i,j,k,row,m;
m=row;
for(i=0;i<m;i++)
{
printf("\n");
for(k=0;k<row;k++)
printf(" ");
for(j=0;j<=i;j++)
printf(" *");
row--;
}
printf("\n");
break;}
default:
break;
}}
return(0);
}
What ?! Another repost ?!
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
am i using this program wrong ??? paul_mat Linux - Software 1 04-09-2006 01:50 AM
why output is wrong ( C Program ) minil Programming 7 02-23-2005 06:05 AM
what's wrong with my program kira Programming 10 01-01-2005 05:30 AM
What is wrong with the program? Xiangbuilder Programming 11 09-15-2003 12:49 AM
what is wrong with my program? nakkaya Programming 1 03-13-2003 02:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration