C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-27-2008, 09:38 AM   #1
Registered User
 
Join Date: Jun 2008
Location: Germany
Posts: 2
Basic problem - need help

Hi,
I am really new to programming and trying to teach myself c and it's not easy! Could someone please tell me why this won't work. it's not finished yet still need to add the sqrt statement. I get stuck at the average calculations.
thanks in advance...
jasemca


Code:
#include <stdio.h>
#include <math.h>

int main()
{
    // Create two new integers to gather values
    int a = 0;
    int b = 0;
    int a+b =c;

    // Get me a number from the user (a)
    printf("Enter a positive whole number.\n");
    scanf("%d", &a);
    printf ("You entered %d.\n", a);

    // Get another number (b)
    printf("Enter a positive whole number.\n");
    scanf("%d", &b);
    printf ("You entered %d.\n", b);

    // Print the average
    scanf("%f",c = (a+b)/2);
    printf ("Average is: %f.\n", c);

    // Print another math function
   
    return 0;
}
jasemca is offline   Reply With Quote
Old 06-27-2008, 09:43 AM   #2
Deathray Engineer
 
MacGyver's Avatar
 
Join Date: Mar 2007
Posts: 3,211
Yeah, that's wrong. I could point out all the errors, but I think you would do best to go over your tutorials/books again.
__________________
MacGyver is offline   Reply With Quote
Old 06-27-2008, 09:46 AM   #3
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
If you study your book(s)/tutorial(s) carefully, I'm sure you'll find the errors.
You are thinking too much math and too little computer/C.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 06-29-2008, 03:00 PM   #4
Registered User
 
Join Date: Jun 2008
Location: Germany
Posts: 2
thanks

Ok guys, thanks....I think! :-)
jasemca is offline   Reply With Quote
Old 06-29-2008, 03:34 PM   #5
Registered User
 
Join Date: Sep 2006
Posts: 2,506
Quote:
Originally Posted by jasemca View Post
Hi,
I am really new to programming and trying to teach myself c and it's not easy! Could someone please tell me why this won't work. it's not finished yet still need to add the sqrt statement. I get stuck at the average calculations.
thanks in advance...
jasemca


Code:
#include <stdio.h>
#include <math.h>

int main()
{
    // Create two new integers to gather values
    int a = 0;
    int b = 0;
       int a+b =c;   //not allowed and not needed  
   //just float c will do fine

    // Get me a number from the user (a)
    printf("Enter a positive whole number.\n");
    scanf("%d", &a);
    printf ("You entered %d.\n", a);
    //to get  rid of the newline char still in the input buffer, you may use:
    getchar();     

    // Get another number (b)
    printf("Enter a positive whole number.\n");
    scanf("%d", &b);
    printf ("You entered %d.\n", b);

    // Print the average
    scanf("%f",c = (a+b)/2);  //this line is unnecessary
   //or c = (a+b)/2; 
   printf("Average is: %f.\n", c);
   printf ("Average is: %f.\n", (a+b/2);
   
    // Print another math function
   
    return 0;
}
Revisions are in red. These are very basic concepts in C. If you don't have a good book, get one. If you have one, you should study it more.
Adak is online now   Reply With Quote
Reply

Tags
basic, beginner, c-code, problem

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] New script engine (Basic sintax) MKTMK C++ Programming 1 11-01-2005 10:28 AM
what are your thoughts on visual basic? orion- General Discussions 16 09-22-2005 04:28 AM
Problem with basic encryption program. mmongoose C++ Programming 5 08-27-2005 04:41 AM
Bin packing problem.... 81N4RY_DR460N C++ Programming 0 08-01-2005 05:20 AM
Words and lines count problem emo C Programming 1 07-12-2005 03:36 PM


All times are GMT -6. The time now is 11:36 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22