473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sharing balance

hello, i m a newbie in c++..i nid u all to help me..how to share the new_balance with void call() and void sms()?

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. void sms();
  3. void call();
  4. void topup();
  5. void logo();
  6.  
  7. void main()
  8. {
  9. logo();
  10. }
  11.  
  12. void logo()
  13. {
  14. printf("[1] Call, [2] SMS, [3] TOP UP, [4] EXIT ? ");
  15.     scanf("%d", &choose);
  16.     if(choose == 1)
  17.     {
  18.     printf("\nYou Have Choosen %s\n", "CALL");
  19.     call();
  20.     }
  21.     else
  22.     {
  23.     }
  24.     if(choose == 2)
  25.     {
  26.     printf("\nYou Have Choosen %s\n", "SMS");
  27.     sms();
  28.     }
  29.     else
  30.     {
  31.     }
  32.     if(choose == 3)
  33.     {
  34.     printf("\nYou Have Choosen %s\n", "TOP UP");
  35.     topup();
  36.     }
  37.     else
  38.     {
  39.     }
  40.     if(choose == 4)
  41.     {
  42.     printf("\nYou Have Choosen %s\n", "EXIT");
  43.     logo();
  44.     }
  45.     else
  46.     {
  47.     }
  48. }
  49. void call()
  50. {
  51. double balance = 10.0, call_duration, new_balance;
  52. printf("The Prepaid Balance = %.2lf\n", balance);
  53. printf("Call Duration(minutes) : ");
  54. scanf("%f", &call_duration);
  55. new_balance = balance - (call_duration * 0.50);
  56. printf("Your new balance = %.2lf", new_balance);
  57. }
  58. void sms()
  59. printf("The Prepaid Balance = %.2lf\n", new_balance);
  60.  
Jun 20 '13 #1
1 1137
weaknessforcats
9,208 Expert Mod 8TB
You need to create new_balance outside these functions. There's no sharing when each function has created its own new_balance.

Next, you pass the address of new_balance to each of the functions.

Next each function dereferences the address to use the shared new_balance.

Expand|Select|Wrap|Line Numbers
  1. float new_balance;
  2. etc...
  3. sms(&new_balance);
  4. call)&new_balance);
  5. etc...
Then inside he functions you dereference the address:

Expand|Select|Wrap|Line Numbers
  1. void sms(float* ptr)
  2. {
  3.    printf("%f", *ptr};
  4. }
Here the function expects the address of a float. That is, a float pointer. The pointer, ptr, is the address of the float which makes *ptr the float itself. The function will work with any float so it is up to yu to pass in the address of the correct float.
Jun 20 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

83
by: theodp | last post by:
While Mainframe and Unix users are unlikely to find it novel that Windows XP allows several family members to share a PC while enabling each to have personalized settings and folders, that's not...
4
by: Steven Stewart | last post by:
Is it possible to do the following? I have a field called BalCarFor (Balance Carried Forward). If the primary key of a new record is identifcal to a primary key of a previous record (except for...
3
by: Greg | last post by:
On my report I want to have an opening balance signifying all transactions up to the month selected and detailed transactions for the month selected and then a closing blance. I'm perpelexed...
13
by: Maria Mela | last post by:
Hello everyone... Anybody can help me on this question, please? i´ve this code in my application: /*for Card creation*/ typedef struct card { etc,etc } Card; typedef Card *PtrCrt;
3
by: Manish | last post by:
I think this question has been asked number of times. However, I am looking for some specific information. Perhaps some of you can help close the gap. Or perhaps you can point me towards right...
3
by: Paul H | last post by:
I have a transactions table and a balance table that look something like this: tblTransactions TransactionID (PK Autonumber) ClientID TransactionDate TransactionAmount (currency field, values...
1
maxx233
by: maxx233 | last post by:
I need to figure out a way to generate a report to find customers in our DB that have unused credits on their account so we can void them out periodically - we manually assign them credits, they make...
1
by: darendaren88 | last post by:
I have created this table: mysql> describe acount; +----------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |...
1
by: blknmld69 | last post by:
How do i get my program to add a $15 fee if the balance falls below $400? import java.util.Scanner; // Needed for the Scanner class public class BankCharges { public...
0
by: Tammy Tappan | last post by:
I have a table that is basically a ledger for a bank account. I have a query that adds in a column for balance, & computes the balance as a running total. Here is the Field: RunningBal:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.