0

HOW DO I COMPARA CHAR INTO A INTGER STRING?

-----------------------------------------------------

#include<string.h>
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<ctype.h>
#define g gotoxy
//*design
void design()
{
int ctr;
for (ctr=0;ctr<9;ctr++)
{
    textcolor(LIGHTBLUE);
    cprintf("--");
}
}
//-------------------------------------------------
void maine()
{
clrscr();
g(8,3);design();
g(8,5);design();
g(27,4);cout<<"DATA STRUCT COMPANY INVENTORY SYSTEM";
int total=0,totalprice=0;
int count,ctr=9;
struct
 {
  char stocknumber[6];
  char itemname[25];
  int currentstock;
  int deliveredstock;
  float price;
  }system;

gotoxy(12,7);  cout<<"*Three letter and Three Number*";
gotoxy(12,8);  cout<<"Enter the Stock Number:" ;
           cin>>system.stocknumber;

do{
  if (system.stocknumber[6] > 7)
  {
   g(12,ctr++);cout<<"Re-Enter the Stock Number:";
   cin>>system.stocknumber;
  }
 else
  {
  count=0;
  break;
  }
}while (count==1);
g(12,ctr++); cout<<"Enter the Item NAME:";
         cin>>system.itemname;
g(12,ctr++); cout<<"Enter the amount of Current Stocks:";
         cin>>system.currentstock;
g(12,ctr++); cout<<"Enter the amount of Delivered Stocks:";
         cin>>system.deliveredstock;
g(12,ctr++); cout<<"Enter the Price(Per Unit): "<<"P ";
         cin>>system.price;


if (system.currentstock > system.deliveredstock)
{
total =system.currentstock-system.deliveredstock;
 if (system.price>0)
 {
totalprice = total * system.price;
 }
}
 else
 {
 g(8,ctr++); cout<<"Wrong Input!"<<"\n";
 }
//-----------------------------------------------------------
clrscr();
int c=7;
g(10,2);design();
g(27,3);cout<<"DATA STRUCT COMPANY INVENTORY SYSTEM";
g(10,4);design();
g(15,c++);cout<<"STOCK NUMBER:     "<<system.stocknumber;
g(15,c++);cout<<"ITEM NAME:        "<<system.itemname;
g(15,c++);cout<<"CURRENT STOCKS:   "<<system.currentstock;
g(15,c++);cout<<"DELIVERED STOCKS: "<<system.deliveredstock;
g(15,c++);cout<<"PRICE:            "<<system.price;
g(15,c++);cout<<"TOTAL STOCKS:     "<<total;
g(15,c++);cout<<"TOTAL PRICE:      "<<totalprice;
}

void main()
{
char rec,pass[10];
int choice=1,ctr,i=15;

while (choice==1)
{
i=15;
cout<<"\n";
g(20,i++);cout<<"MENU:Do you want to add records?";
g(20,i++);cout<<"Select A -ADD RECORDS:";
g(20,i++);cout<<"Select E -EXIT:";
cin>>rec;
rec=toupper(rec);

switch (rec)
 {
case 'A': for (ctr=1;ctr<=3;ctr++)
        {
          g(10,i++);cout<<"\nEnter PASSWORD:";
          gets(pass);
          if (!strcmp(pass,"data"))
          {
        maine(); break;
          }
          else
          {
          g(10,i++);cout<<"\nINVALID PASSWORD!";
          g(10,i++);cout<<"\nNote:Password can valid only thrice";
          }
          if (ctr==3)
          {
          cout<<"INVALID PASSWORD!";
          choice=0;
          }
        }
        break;
case 'E': choice=0;
      break;
default: g(10,i++);cout<<"CHOOSE ONLY ONE! A or E.";
 }
}
clrscr();
textcolor(YELLOW);
g(15,10);cprintf("DATA STRUCT COMPANY SYSTEM");
g(15,11);cprintf("\"Thank You!");
getch();
}

Edited by Reverend Jim: Fixed formatting

Attachments
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
0

convert it to an integer before comparison if( atoi(system.stocknumber) > 7) Your program should validate that the user entered all digits before doing that otherwise atoi() will produce meaningless results.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.