I modify this .cpp code into .c but it gives error:
the original code is:(runs fine)
#include <string>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int c, s[10];
int i, j;
string name;
cout << "Welcome to Airline Reservations System!\n";
for (j=0; j<10; j++)
{
cout << "Please enter your name: ";
getline(cin,name);
cout << "Choose a class: ";
cin >> c;
switch(c)
{
case 1:
cout << "First class" << endl;
cout << "Seats available are 1,2,3,4,5.\n";
do {
cout << "Pick a seat: ";
cin >> s[j];
for (i=0; i<j; i++) if (s[j]==s[i]) {cout << "Seat taken. ";
break;}
} while (i!=j);
if(s[j] <= 5)
{
cout << "\n";
cout << "--------------------------\n";
cout << "Name: " << name << endl;
cout << "Class: " << "First class" << endl;
cout << "Seat no.: " << s[j] << endl;
cout << "--------------------------\n";
}
else
cout << "Wrong number! No seat for you!\n";
break;
case 2:
cout << "Economic class\n";
cout << "Seats available are 6,7,8,9,10.\n";
do {
cout << "Pick a seat number: ";
cin >> s[j];
for (i=0; i<j; i++) if (s[j]==s[i]) {cout << "Seat taken. ";
break;}
} while (i!=j);
if(s[j] >= 6)
{
cout << "\n";
cout << "--------------------------\n";
cout << "Name: " << name << endl;
cout << "Class: " << "Economic class" << endl;
cout << "Seat no.: " << s[j] << endl;
cout << "--------------------------\n";
}
else
cout << "Wrong number! No seat for you!\n";
break;
default:
break;
}
}
system("pause");
return 0;
}
But the converted code doesn't:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{
int c; /*untuk class*/
int i; /*untuk ulang compare s[i]==s[j]*/
int j; /*untuk ulang suruh pilih class*/
char s[10]={'1','2','3','4','5','6','7','8','9','10'}; /*untuk seat*/
printf("Welcome to Airline Reservations System!\n");
for (j=0; j<10; j++)
{
printf("Choose 1 for First Class and 2 for Economic class\n");
printf("Choose a class:\t");
scanf("%d",&c);
switch(c)
{
case 1:
printf("First class\n");
printf("Seats available are 1,2,3,4,5.\n");
do
{
printf("Pick a seat: ");
scanf("%s",s[j]);
for (i=0; i<j; i++)
if (s[j]==s[i])
{
printf("Seat taken.\n");
break;
}
}
while (i!=j);
if(s[j] <= 5)
{
printf("\n");
printf("--------------------------\n");
printf("Class: First class\n");
printf("Seat no : %s",s[j]);
printf("--------------------------\n");
}
else
printf("Wrong number! No seat for you!\n");
break;
case 2:
printf("Economic class\n");
printf("Seats available are 6,7,8,9,10.\n");
do
{
printf("Pick a seat number: ");
scanf("%s",s);
for (i=0; i<j; i++)
if (s[j]==s[i])
{
printf("Seat taken.\n");
break;
}
}
while (i!=j);
if(s[j] >= 6)
{
printf("\n");
printf("--------------------------\n");
printf("Class: Economic class\n");
printf("Seat no: %s",s[j]);
printf("--------------------------\n");
}
else
printf("Wrong number! No seat for you!\n");
break;
default:
break;
}
}
system("pause");
return 0;
}
Somebody help me please. i'm a newby. just started learning c standard few weeks ago.