Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
3.48/5 (14 votes)
See more:
C++
#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 16-Oct-22 20:03pm
v2
Comments
[no name] 5-Nov-20 12:56pm    
Simple question.

Just using printf, scanf functions instead of cout, cin.
Solution code is:

C++
<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); 
}
 
Share this answer
 
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
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[^]).
 
Share this answer
 
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

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