i need help as soon as possible help me convert this to c program

  #include <iostream>
  #include <iomanip>
  using namespace std;

  int main()
  {
 //declare variables
 int totalCals = 0;
 int fatGrams = 0;
 int fatCals = 0;
 double fatPercent = 0.0;

 //enter input items
 cout << "Total calories: ";
 cin >> totalCals;
 cout << "Grams of fat: ";
 cin >> fatGrams;

 //determine whether the data is valid
 if (totalCals >= 0 && fatGrams >= 0)
 {
 //calculate and display the output
 fatCals = fatGrams * 9;
 fatPercent = static_cast<double>(fatCals)
 / static_cast<double>(totalCals) * 100;

 cout << "Fat calories: " << fatCals << endl;
 cout << fixed << setprecision(0);
 cout << "Fat percentage: " << fatPercent << "%" << endl;
 }
 else
 cout << "Input error" << endl;
 //end if

 system("pause");
 return 0;
 }
 //end of main function

//end of main function

There aren't many c++ elements that need changing. Look at cin, cout, the use of static_cast<>, and the #include directives and you should be good.

can you give me example ? im stress , over this program .

Do you know how to output in C? Do you know to cast to different types in C?

seriously i dont know . can you help convert it for me .

You can print things using the printf function (instead of cout), as is explained in details here.

You can get user input using the scanf function (instead of cin), as is explained in details here.

The header you need to include for both is <stdio.h> (instead of <cstdio> as said in the C++ reference on the C libraries).

And the casts can simply be done as C-style casts.

That is about as much help as I can provide. We cannot just do it for you. You are obviously doing this to learn, so you need to be doing this by yourself.

thank you all , i have solve it , haha . thanks for helping me . thanks a lot ! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.