3 Replies - 716 Views - Last Post: 29 September 2015 - 07:50 PM Rate Topic: -----

#1 westin467   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 27-September 15

Scanf() with height width and depth

Posted 29 September 2015 - 07:01 PM

Problem) Consider the following code with scanf() function. Assume that the user who runs this code wants to assign 10, 4 and 5 to height, width and depth respectively.

What are you going to see if you run this code and want to enter the mentioned values? (Write everything that is printed and entered)
#include <stdio.h> int main() {
int height, width, depth;
printf(“Enter the height:”); scanf(“%d", &height);
printf(“\nEnter the width:”); scanf(“%d", & width);
printf(“\nEnter the depth:”); scanf(“%d", & depth);
printf("The volume is: %d", height*width*depth); }


My attempt: when I run this code, it simply gives me an error. I am not sure what to do then. Any help would be appreciated. This is how I tried inputting it along with many other ways.
#include <stdio.h> int main() {
int height, width, depth;
int height=10
int width=4
int depth=5
printf(“height:”); scanf(“%d", &height);
printf(“\nwidth:”); scanf(“%d", & width);
printf(“\ndepth:”); scanf(“%d", & depth);
printf("The volume is: %d", height*width*depth); 
}


This post has been edited by Skydiver: 29 September 2015 - 07:04 PM
Reason for edit:: Put code in code tags. Learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: Scanf() with height width and depth

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7915
  • View blog
  • Posts: 26,425
  • Joined: 05-May 12

Re: Scanf() with height width and depth

Posted 29 September 2015 - 07:06 PM

The intent of the assignment is for you to predict the behavior of the program, not actually run the program.

Anyway the issue is that C only uses one kind of double quote, but the code that you copied and pasted is using the "smart" opening and closing double quotes.

In the future, when you encounter errors, be sure to also post the errors and warnings that you get verbatim. Don't paraphrase. Don't trim. There is important information in the error messages and warnings that will help find the source of a problem.
Was This Post Helpful? 0
  • +
  • -

#3 westin467   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 27-September 15

Re: Scanf() with height width and depth

Posted 29 September 2015 - 07:31 PM

Isn't the behavior of the program just multiplying the length*width*depth together?

This post has been edited by Skydiver: 30 September 2015 - 05:44 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 #define   User is offline

  • Cannot compute!
  • member icon

Reputation: 1868
  • View blog
  • Posts: 6,763
  • Joined: 19-February 09

Re: Scanf() with height width and depth

Posted 29 September 2015 - 07:50 PM

Quote

(Write everything that is printed and entered)


Isn't that the behavior of the program?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1