Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jan 26th, 2005, 6:54 AM   #1
Border Fox
Newbie
 
Join Date: Jan 2005
Posts: 5
Rep Power: 0 Border Fox is on a distinguished road
URGENT HELP NEEDED: Whats wrong with my code?

The code below should take a user entered floating point number and use functions SEPARATE (to break the number up into its individual parts) and PRINTOUT ( to display the individual parts ).
despite my best efforts i seem to be up against a brick wall due to my inexperience.

according to my compiler there are errors on:

num.cpp: In function `int main()':
num.cpp:29: error: syntax error before `(' token
num.cpp: In function `void separate(number)':
num.cpp:37: error: syntax error before `;' token
num.cpp:41: error: non-lvalue in assignment
num.cpp:42: error: non-lvalue in assignment

can anyone help me and sort out these errors? better still, could anyone find a better way of solving the above task because i dont think mine is ever guna work!
I think i needa use FLOOR & FABS in the separate funciton but i dont know how to.


_________________________________________________________________________
1 #include <iostream>
2
3 using std::cout;
4 using std::cin;
5 using std::endl;
6
7 #include <cmath>
8
9 struct number {
10 double initial;
11 char sign;
12 int mag;
13 double fract;
14 };
15
16 void separate ( struct number );
17
18 void printOut ( struct number );
19
20 int main ()
21 {
22 number value;
23
24 cout << "Input a real number (one with decimal point): " << endl;
25 cin >> value.initial;
26
27 separate ( value )
28
29 printOut ( value )
30
31 return 0;
32 }
33
34 void separate ( struct number value )
35 {
36 if ( value.initial > 0 )
37 value.sign = +;
38 else
39 value.sign = -;
40
41 floor ( value.initial ) = value.mag;
42 value.initial - value.mag = value.fract;
43
44 }
45
46 void printOut ( struct number value )
47 {
48 cout << "Number to be analysed: " << value.initial << endl;
49 cout << "Sign: " << value.sign << endl;
50 cout << "Whole number: " << value.mag << endl;
51 cout << "Fractional part: " << value.fract << endl;
52 }

__________________________________________________________________________
Border Fox is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:06 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC