Click here to Skip to main content
14,733,262 members
Please Sign up or sign in to vote.
3.48/5 (14 votes)
See more:
#include<iostream>
#include<string>

using namespace std;

int askBills(string prompt);
void totalExpenses(int car,int rent,int food,int phone,int gas,int util);

int main(){
    
cout << "Manage your budget and see how much you can save!\n\n";

int income = askBills("\nMonthly income:$ ");
int car = askBills("\nCar payment:$ ");   
int rent = askBills("\nMonthly rent:$ ");
int food = askBills("\nFood expenses:$ ");
int phone = askBills("\nPhone bill:$ ");
int gas = askBills("\nEstimated gas expenses:$ ");
int util = askBills("\nMonthly utilities:$ ");

totalExpenses(car, rent, food, phone, gas, util);

   
system("pause");   
return 0;    
}
int askBills(string prompt){
int bill;
cout << prompt;
cin >> bill;
return bill;       
}
void totalExpenses(int car,int rent,int food,int phone,int gas,int util){
cout << "\nYour monthly expenses:$ "<<car+rent+food+phone+gas+util <<="" endl;="" 
}

What I have tried:

<b="">What I have tried:

This is my coging, but i need to convert it to c
Posted
Updated 5-Nov-20 8:26am
v2
Comments
[no name] 5-Nov-20 12:56pm
   
Simple question.

That is already very C-like code.
Just substitute cout, cin method calls with correspondig calls to printf, scanf functions (see, for instance C printf and scanf functions with example[^]).
   
Comments
Maciej Los 12-May-20 3:39am
   
5ed!
Member 14984954 5-Nov-20 12:40pm
   
Not a good answer
CHill60 5-Nov-20 16:48pm
   
Why not? Seems quite clear to me
[no name] 5-Nov-20 12:51pm
   
You didnt give a proper answer. Simply linked to some sources.
CPallini 5-Nov-20 16:43pm
   
And you made a fresh account just to downvote me?
I'm honored. :-D
Patrice T 5-Nov-20 14:14pm
   
+5 counter vote.
CPallini 5-Nov-20 16:41pm
   
Thank you Patrice.
Just using printf, scanf functions instead of cout, cin.
Solution code is:

<pre>
#include<stdio.h>
#include<string.h>
int askBills(char[] prompt);
void totalExpenses(int car,int rent,int food,int phone,int gas,int util);

int main(){
    
printf("Manage your budget and see how much you can save!\n\n");

int income = askBills("\nMonthly income:$ ");
int car = askBills("\nCar payment:$ ");   
int rent = askBills("\nMonthly rent:$ ");
int food = askBills("\nFood expenses:$ ");
int phone = askBills("\nPhone bill:$ ");
int gas = askBills("\nEstimated gas expenses:$ ");
int util = askBills("\nMonthly utilities:$ ");

totalExpenses(car, rent, food, phone, gas, util);

   
system("pause");   
return 0;    
}
int askBills(char[] prompt){
int bill;
printf("%s",prompt);
scanf("%d", bill);
return bill;       
}
void totalExpenses(int car,int rent,int food,int phone,int gas,int util){
printf("\nYour monthly expenses: %d\n"<<car+rent+food+phone+gas+util); 
}
   
v2
Comments
[no name] 5-Nov-20 12:22pm
   
Hi,
This works I have tested it on my linux machine
Thanks.
[no name] 5-Nov-20 12:26pm
   
Hi,
Thanks for trying out the solution.
Thanks
[no name] 5-Nov-20 12:34pm
   
Thanks for converting it buddy.
CHill60 5-Nov-20 16:53pm
   
Exactly what CPallini suggested months ago. Sounds like you were too lazy to do the work and just wanted something you could cut & paste

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900