|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: C Programming Homework Help Needed
Pat,
It looks like you are not being consistant with the data type for "color". You are inputting it as an integer (%d) so I'll assume you've defined it as such, however you are comparing it in the switch statement as a character. The value '0' will be converted to it's ASCII value (48) for the compare. If 'color' is an integer, then I'd try removing the single quotes from around the numbers in the case statements and see if that works. Mike |
|
#2
|
||||
|
||||
|
Re: C Programming Homework Help Needed
Quote:
|
|
#3
|
||||
|
||||
|
Re: C Programming Homework Help Needed
I think I need to make this the "Help Pat pass EGR 261" thread.
My problem this time is that a switch statement again. After the menu displays, the user can enter a selection, but when they hit enter, it just displays a blank line and doesn't leave the switch statement. Thanks for the continuing help guys. Code:
int menu_error;
int menu_selection;
do
{
do
{
menu_error = 0;
/* Displays main menu */
printf("Please select from the following options:\n");
printf("(1) Draw a colored shape\n");
printf("(2) Clear graphics window\n");
printf("(3) Exit\n=>");
fflush(stdin);
scanf("%d\n", &menu_selection);
switch(menu_selection)
{
case 1:
draw_shape();
break;
case 2:
clear_graphics();
break;
case 3:
break;
default:
menu_error = 1;
printf("Please enter a selection 1, 2, or 3");
}
}
while(menu_error);
}
while(menu_selection != 3);
|
|
#4
|
|||
|
|||
|
Re: C Programming Homework Help Needed
Pat,
I'm not sure the problem is in the switch statement. Try removing the \n from the menu_selection scanf line ("%d" rather than "%d\n") Mike |
|
#5
|
||||
|
||||
|
Re: C Programming Homework Help Needed
That was it! Thanks again!
|
|
#6
|
||||
|
||||
|
Re: C Programming Homework Help Needed
Back again!
I can't figure out how to convert a float value to a char string. Suggestions? Thanks! |
|
#7
|
||||
|
||||
|
Re: C Programming Homework Help Needed
Quote:
Idk how you would get each number individually but to change the number into its ASCII code you would do # + '0' to get the ascii code of the number |
|
#8
|
||||
|
||||
|
Re: C Programming Homework Help Needed
Well, I have a float variable that I need to be able to display using WinBGI using the text function that only accepts char strings. So, I really don't know exactly.
|
|
#9
|
|||
|
|||
|
Re: C Programming Homework Help Needed
The function you are looking for is called "sprintf".
Use it just like you would use printf to print a float. The trick is that it throws it into a string, rather than at the console. Code:
char * buffer = new char[10]; float f = 12.4; sprintf(buffer,"%f",f); |
|
#10
|
||||
|
||||
|
Re: C Programming Homework Help Needed
Is there a header file you need to include?
I'm getting a 'no prototype for function' error for the sprintf function. |
|
#11
|
|||
|
|||
|
Re: C Programming Homework Help Needed
I believe you need to include stdio.h.
|
|
#12
|
||||
|
||||
|
Re: C Programming Homework Help Needed
That made that error go away but I still don't really understand how to use the function.
The first line: char * buffer = new char[10]; is confusing me. |
|
#13
|
|||
|
|||
|
help on palindrome
i have make a program that can trace palindrome number but i need it to loop over and over again till i keyin -1 then only the program terminate this is the code that i have used: Code:
#include<stdio.h>
#include<string.h>
void main()
{
char strsrc[5];
char strtmp[5];
printf("\n Enter a five-digit number ( -1 to end ): "); gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n %s is a palindrome\n",strsrc);
else
printf("\n %s is not a palindrome\n",strsrc);
}
|
|
#14
|
|||||
|
|||||
|
Re: C Programming Homework Help Needed
Quote:
You want it to end? Hint: use an exit statement, but only execute it when the program is supposed to terminate. |
|
#15
|
||||
|
||||
|
Re: C Programming Homework Help Needed
What exactly do you mean by "loop"? Do you want it to repeatedly ask for a number, then check it for palindrome-ness (sorry, vocabulary suffered a non-Build season hit
) , or do you want to loop through calculations (a bit daft, but I don't know what the professor/employer expects...), or what? |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| programming help needed | krunal | Programming | 3 | 29-01-2007 00:18 |
| Help on a Homework Assignment. | Pavan Dave | General Forum | 1 | 13-09-2006 14:20 |
| HELP-URGENT PROGRAMMING HELP NEEDED | Rohith Surampudi | Lego Mindstorm Discussion | 1 | 24-03-2006 23:05 |
| URgent Programming Help needed | rcubes85 | Programming | 4 | 15-02-2005 23:21 |