LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2004, 10:54 AM   #1
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Rep: Reputation: 0
C Programming HELP!!!


I have played with this for a while and need a fresh set of eyes to help me if you will:
I have to write a program which asks for an integer number and stores as num. add num to total . Do this 6 times and calculate the average. Display total and average. Must reuse same variable.

This is what I have so far:


#include <stdio.h>

int main()

{
int num, avg, total;

total = 0;

printf("Enter an integer:");
scanf("%f", &num);
total = total+num;

printf("\n Enter an integer:");
scanf("%f", &num);
total = total + num;

printf("\n Enter an integer:");
scanf("f%", &num);
total = total+num;

printf("\n Enter an integer:");
scanf("%f:, &num);
total = total+num;

printf("\n Enter an integer:");
scanf("%f:, &num);
total = total+num;

printf("\n Enter an integer:");
scanf("%f:, &num);
total = total+num;

avg = total / 6.0;

printf("\n The total is %f", total);

printf("\n The average of the six numbers is %f", avg);

return 0;
}



I get the following errors when I run my compiler:

23: Unterminated string or character constant in function main()
24: Function call missing ) in function main()

These errors repeat on lines 27, 28, 31, & 32.
Any help would be appreciated. Explanations for what I am doing wrong will really be appreciated.

Ripwheels8
 
Old 11-11-2004, 11:01 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Before seeking help from others, you should first try to find by yourself.
The error message is very clear, you have an unterminated string in line 23, just look better here.

And instead of cut and paste, try using the for() loop.
 
Old 11-11-2004, 11:02 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
this is (in my opinion) clearly a homework question, and as such not really what LQ.org is here for. you need to learn how to code yourself, not get answers from other people.

you do though have very obvious syntax errors on those lines, which aren't even the same as the ones which precede it.
 
Old 11-11-2004, 11:21 AM   #4
djgerbavore
Member
 
Registered: Jun 2004
Location: PA
Distribution: Fedora (latest git kernel)
Posts: 458

Rep: Reputation: 30
check you scanf lines....man scanf if you don't see it right away..
 
Old 11-11-2004, 11:22 AM   #5
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Original Poster
Rep: Reputation: 0
I fixed the syntax errors. Thank you for pointing out the fact that the code lines weren't the same. I am new at this programming thing and if I don't know what something means and cannot find it in a book, how am I supposed to learn what to do. A friend of mine told me about this site and how helpful people were. That is why I asked this question. Thank you for your assistance.
 
Old 11-11-2004, 11:24 AM   #6
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Original Poster
Rep: Reputation: 0
I have no errors when I run the compipler, but it will not add the numbers together.
 
Old 11-11-2004, 11:39 AM   #7
masand
LQ Guru
 
Registered: May 2003
Location: INDIA
Distribution: Ubuntu, Solaris,CentOS
Posts: 5,522

Rep: Reputation: 69
the problem is that u need to use float data type for all ur variables


like
float num, toatal,avg;
 
Old 11-11-2004, 11:43 AM   #8
ripwheels8
LQ Newbie
 
Registered: Jul 2004
Posts: 9

Original Poster
Rep: Reputation: 0
GOT IT, THANK YOU VERY MUCH masand.
 
Old 11-11-2004, 12:14 PM   #9
phoenix7
Member
 
Registered: Aug 2004
Distribution: Mandrake 10.2(Mandriva), SuSE 9.3, Slackware 9.1, Xandros 3.1, Knoppix 3.9, FreeBSD 5.3, RedHat9
Posts: 122

Rep: Reputation: 15
you can read a number with %f then store it to an int variable.
scanf converts number to floating point representation then copy it to &x. you can read it as int.
casting is not performed in this case.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM
im new to programming but..... boxerboy Programming 6 08-26-2005 06:17 AM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
C programming oranj Linux - Networking 1 12-07-2004 12:40 AM
Qt Programming... jinksys Programming 1 08-06-2003 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration