My very first program, is not working :-/? [C]

Lumia925

Estimable
Oct 16, 2014
68
0
4,590
3
This is the first time I typed a program on my laptop, and it's not working as expected.
Here's what it looks like:

And here's a trial run:


What exactly am I doing wrong? Thanks for your help..

Okay, the source code is too minuscule to read, here's a copy/paste of the source code..

C++:
#include<stdio.h>
int main()
{
	char name[20];
	int item=0;
	float cost=0;
	printf("Enter item name, followed by return \n");
	scanf( "%[^\n]", name); //[^\n] forces scanf to accept ALL input until ENTER is pressed
	printf("Enter item number, followed by return (no space allowed) \n");
	scanf( "%d", &item);
	printf("Enter cost, followed by return (decimal values allowed) \n");
	scanf( "%f", &cost);
	printf("Here's what's stored in the computer's RAM \n");
	printf("Item name = %s \n", name);
	printf("Item number = %d \n"), item;
	printf("Item cost =%f \n"), cost;
	getch();
	return 0;
}
 

Lumia925

Estimable
Oct 16, 2014
68
0
4,590
3


didn't understand... the last printf looks fine to me, where is the error? can you write the correct printf please?
 

Lumia925

Estimable
Oct 16, 2014
68
0
4,590
3


Okay gotcha, damn, such a silly error :p
Here's what the correct code should look like:
C++:
#include<stdio.h>
int main()
{
	char name[20];
	int item=0;
	float cost=0;
	printf("Enter item name, followed by return \n");
	scanf( "%[^\n]", name); //[^\n] forces scanf to accept ALL input until ENTER is pressed
	printf("Enter item number, followed by return (no space allowed) \n");
	scanf("%d", &item);
	printf("Enter cost, followed by return (decimal values allowed) \n");
	scanf("%f", &cost);
	printf("Here's what's stored in the computer's RAM \n");
	printf("Item name = %s \n", name);
	printf("Item number = %d \n", item);
	printf("Item cost =%f \n", cost);
	getch();
	return 0;
}
Thank you so much for you help bro :)
 
Thread starter Similar threads Forum Replies Date
L Apps General Discussion 1
ssmana Apps General Discussion 6
A Apps General Discussion 3
M Apps General Discussion 1
UItmaWepn Apps General Discussion 0
S Apps General Discussion 9
S Apps General Discussion 2
shiftyape Apps General Discussion 8
D Apps General Discussion 1
P Apps General Discussion 3
viveknayyar007 Apps General Discussion 0
shiftyape Apps General Discussion 18
C Apps General Discussion 3
shiftyape Apps General Discussion 1
R Apps General Discussion 9
j_a_k_e_24 Apps General Discussion 1
John_VanKirk Apps General Discussion 5
R Apps General Discussion 1
fdd2blk Apps General Discussion 3
C Apps General Discussion 1

ASK THE COMMUNITY

TRENDING THREADS