Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

C program doesnt show right output

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

this is a very simple C test the output makes no sense to me. The code is:



The out put is :

Success




It doesnt change line it should be like:



I am using the online compiler "ideone".

Any advice?

Regards,
Isaac
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code doesn't print any newline characters, so it's not surprising that there aren't any in the output.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now for the this code:




the input :




It shows a result that makes no sense


Any idea?

Regards
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In which way does it not make sense? What do you think it should have printed?
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the code:





should be the values I in the input (30,23,20)

Also

is an output for the sentence :

when I is the the output of the operation so the output (I) should not be -0.00 like it seems to be in this program



Regads,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, you should not have line break characters "\n" in your scanf format strings. Remove the "\n" from those strings.

Isaac Ferguson wrote:


Second, look at this line:

Isaac Ferguson wrote:


You specify four placeholders: %d, %d, %t, %3.2f
But then you pass only one value, I, to the function.
Also, %t is an invalid placeholder character, you probably meant %d.

You need to pass a value for each of the placeholders. Also, since your variables c and r are floats, you should not use %d, which is for integers, you should use %f instead:

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it works.

Thanks

Regards,
Isaac
 
You showed up just in time for the waffles! And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic