Hi! I need help with my assignment. I need to convert this one to C language. I've already changed the cout to prinf, but somehow it doesn't run. Help please.

#include <stdio.h>

int main(){
int order,no_deals;
cout<<"Grocery"<<endl;
cout<<endl;
cout<<"(1)  Eggs                          6 pesos only."<<endl;
cout<<"(2)  1 kl Rice                     60 pesos only."<<endl;
cout<<"(3)  Milk                          87 pesos only."<<endl;
cout<<"(4)  Pork                          99 pesos only."<<endl;
cout<<"(5)  Salt                          15 pesos only."<<endl;
cout<<"(6)  Soy Sauce                     26 only."<<endl;
cout<<endl;
cout<<"Please select the order number: ";
cin>>order;
cout<<"Please enter the number of deals: ";
cin>>no_deals;
cout<<endl;
switch(order) {

        case 1:
    cout<<"Order : Eggs."<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 6 pesos only."<<endl;
    cout<<"Total price : "<<""<<6*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;
        case 2:
    cout<<"Order Rice"<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 60 pesos only."<<endl;
    cout<<"Total price : "<<""<<60*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;
            case 3:
    cout<<"Order : Milk"<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 87 pesos only."<<endl;
    cout<<"Total price : "<<""<<87*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;
            case 4:
    cout<<"Order : Pork"<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 99 pesos only."<<endl;
    cout<<"Total price : "<<""<<99*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;
            case 5:
    cout<<"Order : Salt"<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 15 pesos only."<<endl;
    cout<<"Total price : "<<""<<15*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;
            case 6:
    cout<<"Order : Soy Sauce"<<endl;
    cout<<"Number of deals : "<<no_deals<<endl;
    cout<<"Price of each deal: 26 pesos only."<<endl;
    cout<<"Total price : "<<""<<26*no_deals<<" pesos "<<"only."<<endl;
    cout<<endl;
    cout<<"Thank you very much!"<<endl;
    break;

} return 0;
}

You wrote you converted to using printf() but the code above doesn't show your work so I can't see what the issue is.

But to the topic question there are many ways.

  1. Line by line conversion.
  2. Functional conversion. That is, you write a new app that does what the old app did.
  3. Consider this is not a very new question as you read https://www.quora.com/Can-we-convert-c++-program-to-c-language
Be a part of the DaniWeb community

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