Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

syntax error ??

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hello i am a new user to the c language also programming i have come across a problem whilst compiling my programme it is coming up with syntax error '}' ??? i dont know why either this is my source code

#include <stdio.h>
#include <conio.h>
#include <ctype.h>

void main()

{
char deg,

float temp,
kelvin;



deg = toupper(getch());
do

{
printf(&quot;\nPlease enter the Degrees you want to use > &quot;);
scanf(&quot;%c&quot;,°);

switch (deg)
{
case 'C': printf(&quot;\nPlease enter the tempeture to convert to kelvin > &quot;);
scanf(&quot;%f&quot;,&temp);

kelvin = temp + 273;

while (kelvin <= 0);
{
printf(&quot;Invalid&quot;);
}
printf(&quot;the results is %f&quot;,kelvin);
}
}
}
i thank you in advance.
 
i know the scanf(&quot;%c&quot;,°); function isnt correct after pasting it on here but it should read

scanf(&quot;%c&quot;,&deg);

 
your stmt

char deg,

has a comma at the end, not a semi-colon...
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
the syntax fo do while is:
do
{
}while(SomeThing...);
you forgot both, while and ; John Fill
1c.bmp


ivfmd@mail.md
 
>#include <stdio.h>
>#include <conio.h>
>#include <ctype.h>

>void main()

int main()

>{
>char deg,

char deg;

>
>float temp,
> kelvin;


>
>deg = toupper(getch());
> do

> {
>printf(&quot;\nPlease enter the Degrees you want to use > &quot;);

fflush(stdout);

> scanf(&quot;%c&quot;,°);

This was munged:

scanf(&quot;%c&quot;,&\deg); /* Ignore the backslash */

> switch (deg)
> {
> case 'C': printf(&quot;\nPlease enter the tempeture to convert to kelvin > &quot;);

fflush(stdout);

> scanf(&quot;%f&quot;,&temp);
>
> kelvin = temp + 273;

> while (kelvin <= 0);

while (kelvin<=0)

> {
> printf(&quot;Invalid&quot;);
> }

Wow, you aren't very forgiving of your users are you? This loops forever if they enter an &quot;Invalid&quot; number.

> printf(&quot;the results is %f&quot;,kelvin);

printf(&quot;the results is %f\n&quot;,kelvin);

> }
> }

This brace should be followed by a while(/*something*/);

>}

[Hoping this wasn't a homework question to see if the students could find all the errors]

Russ
bobbitts@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top