Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 03-10-2010, 05:37 PM   #1
Go4Expert Member
 
Join Date: Jan 2010
Posts: 49
Thanks: 14
Thanked 2 Times in 2 Posts
Rep Power: 0
askmewhy25 is on a distinguished road
Question

How to capture strings or char inputs using atoi/atof if your range is 0?


How to capture strings or char inputs using atoi/atof if your range is 0
becuse my programs continue if the input is a char or string due to that the
string or char is read or equal to zero..

Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

int a(double sales,double sepcost)
{
    double NRV;
    NRV=sales-sepcost; 
    printf("The Net Realizable Value is: %.3lf\n",NRV);

}
int main()
{
    double sales,sepcost;
    char error[128];
  
    do{
      system("cls");
      printf("Please input your Sales Value: \n");
      scanf("%s",&error);
      sales=atof(error);
      printf("Please input your Separable Cost: \n");
      scanf("%s",&error);
      sepcost=atof(error);
      if(sales<0){
        system("cls");
        printf("Invalid input for Sales, Please try again!!\n");
        system("pause");
        }
      if(sepcost<0){
        system("cls");
        printf("Invalid input for Seperabe Cost, Please try again!!\n");
        system("pause");
        }
      }while(sales<0||sepcost<0);
      a(sales,sepcost);

getch();
}
askmewhy25 is offline   Reply With Quote
Old 03-19-2010, 02:50 PM   #2
Banned
 
arunlalds's Avatar
 
Join Date: Mar 2010
Location: India
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
arunlalds is on a distinguished road

Re: How to capture strings or char inputs using atoi/atof if your range is 0?


arunlalds is offline   Reply With Quote
Old 03-19-2010, 03:41 PM   #3
Light Poster
 
Join Date: Sep 2009
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
itstimetojazz is on a distinguished road

Re: How to capture strings or char inputs using atoi/atof if your range is 0?


what characters or strings are given as input to the atof in the above program?
itstimetojazz is offline   Reply With Quote
Old 03-19-2010, 11:41 PM   #4
Skilled contributor
 
virxen's Avatar
 
Join Date: Nov 2009
Posts: 217
Thanks: 2
Thanked 76 Times in 65 Posts
Rep Power: 2
virxen has a spectacular aura aboutvirxen has a spectacular aura about

Re: How to capture strings or char inputs using atoi/atof if your range is 0?


in c++ you can do this

Code:
#include <iostream>
#include <conio.h>

int a(double sales,double sepcost){
    double NRV;
    NRV=sales-sepcost; 
    printf("The Net Realizable Value is: %.3lf\n",NRV);

}
int main()
{
    double sales,sepcost;
    char error[128];
  
    do{
      system("cls");
      printf("Please input your Sales Value: \n");
            
      
      std::cin>>sales;

      if (std::cin.fail()){             
          std::cin.clear();
          std::cin.ignore(std::numeric_limits<int>::max(),'\n');
          sales=-1;
      }
            if(sales<0){
        system("cls");
        printf("Invalid input for Sales, Please try again!!\n");
        system("pause");
        }else{
      
      printf("Please input your Separable Cost: \n");
      std::cin>>sepcost;
      if (std::cin.fail()){             
          std::cin.clear();
          std::cin.ignore(std::numeric_limits<int>::max(),'\n');
          sepcost=-1;
      }
      

      if(sepcost<0){
        system("cls");
        printf("Invalid input for Seperabe Cost, Please try again!!\n");
        system("pause");
        }
    }
      }while(sales<0||sepcost<0);
      a(sales,sepcost);

getch();
}
virxen is offline   Reply With Quote
The Following User Says Thank You to virxen For This Useful Post:
askmewhy25 (03-20-2010)
Reply  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

All times are GMT +5.5. The time now is 04:14 PM.