Jump to content

ЗАДАЧА НА С++


Recommended Posts

Есть задача необходимо проверить на ввод букв, чтобы при вводе буквы выдавалось что необходимо ввести цифры. Как можно это сделать? Вот текст программы:

#include <iostream.h>

#include <fstream.h>

#include <string.h>

#include <sys\stat.h>

#include <fcntl.h>

#include <conio.h>

#include <stdlib.h>

#include <stdio.h>

void main()

{

cout<<"\n L.r.1\n";

cout<<"\n V OTK naxoditsa N0 priborov, gotovyachixsa k proverke i postypauchix v\n";

cout<<"\n ocered s lamda,propusknaya sposobnost OTK -mu,opredelit T, Nt, fi\n";

char a;

float T, Nt, fi;

do

{

int N0=0;

float lamda=0, mu=0, t=0;

clrscr();

while (N0<=0)

{

if (N0<0)

cout<<"N0>0 Try again!";

cout<<"Vvedite N0:";

cin>>N0;

cout<<"\n";

}

a:

if (mu<lamda)

{

cout<<"lamda<mu, Try again!";

lamda=0;

mu=0;

}

while (lamda<=0)

{

if (lamda<0)

cout<<"lamda>0 Try again";

cout<<"VVedite lamda:";

cin>>lamda;

cout<<"\n";

}

while (mu<=0)

{

if (mu<0)

cout<<"mu>0 Try again";

cout<<"Vvedite mu:";

cin>>mu;

cout<<"\n";

}

if (mu<lamda)

goto a;

while (t<=0)

{

if (t<0)

cout<<"t>0 Try again";

cout<<"Vvedite t:";

cin>>t;

cout<<"\n";

T=N0/(mu-lamda);

Nt=N0-t*(mu-lamda);

fi=lamda/mu;

cout<<"Resultati':\n\n";

cout<<"Vremya isceznoveniya ocheredi T:"<<T;

if (Nt<0)

Nt=0;

cout<<"\n\nKol-vo zayavok v ocheredi Nt:"<<Nt;

cout<<"\n\nKoef. zagruzki sistemi' fi:"<<fi;

cout<<"\n";

getch();

ofstream out ("L\R1.txt");

out<<"Results:\n";

out<<"\nT="<<T;

out<<"\nNt="<<Nt;

out<<"\nfi="<<fi;

out.close();

cout<<"Exit? No(n)\Yes(y)";

cin>>a;

}

} while (a!='y');

clrscr();

}

Link to comment
Share on other sites

Используй функции scanf & printf с аргументом %s и после ввода проверяй буфер на atoi

Link to comment
Share on other sites

Siesta:

Все предельно просто. В языке Си для символы и цифры можно описывать типом char. Внутреннее представление этого типа - это код символа в таблице ASCII.

Мы просто проверяем, кодирует ли код символ или нет. И в зависимости от этого хвалим или ругаем пользователя!!!

# include <stdio.h>void main(){char c;scanf ("%c",&c);if (c>47&&c<58) printf ("molodec");else printf ("durak");}

PS: Простите за несерьезное поведение в написании программы)))))

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...