1
I am learning functions now in c++ and I went to try to run this program. It turns out that when I run it just doesn’t let me type in the value of cin>>p;
it simply ignores the command and switches to the next one. I don’t know what’s going on. This is the program:
#include <iostream>
#include <conio.h>
using namespace std;
float p,mai=0;
int i;
char nome,pesado;
void topo(){
system("cls");
cout<<"------------------------------------"<<endl;
cout<<" D E T E C T O R DE P E S A D O"<<endl;
cout<<" Maior peso ate agora: "<<mai<<" kg"<<endl;
cout<<"------------------------------------"<<endl;
}
int main (void) {
topo ();
do{
i+=1;
cout<<"Digite o nome e depois o peso: "<<endl;
cin>>nome;
cout<<"\n";
cin>>p;
if (p>mai){
mai =p;
pesado =nome;
}
topo();
}while(i<=5);
topo();
cout<<"A pessoa mais pesada foi "<<pesado<<"com "<<mai<<" kg"<<endl;
}
Is there any way you can put the input you are going through? I need it Verbatim, with neither left nor missing a space or enter
– Jefferson Quesado
Look how Marconi put the input of the data in his doubt in this question: https://answall.com/q/211315/64969
– Jefferson Quesado
@Jeffersonquesado this way ?
– Pedro Afonso
You left your code unreadable and didn’t put any input
– Jefferson Quesado
When you talk about input, you talk about what exactly ? regarding the code, was to leave it the way it was ? I didn’t quite understand what you asked me to do, sorry, I’m starting to agr.
– Pedro Afonso
When speaking input is in the sense of what will be passed to the program by the default input (usually the keyboard). For example, look at this question http://br.spoj.com/problems/COFRE/, it has the input example. This other problem has 3 input examples: http://olimpiada.ic.unicamp.br/pratique/programacao/nivel2/2007f1p2_choc
– Jefferson Quesado
and the "Cin>" commands are no longer sufficient for input ?
– Pedro Afonso
I didn’t ask how you did it to get the down payment, but what’s the down payment.
cin >> nome;
indicates how you received programmatically input, but I don’t know if you typed inp
orPedro
orPedro Alonso
orumgrandenomedetestequeultrapassaacapacidadedeleituradaparadadastring
– Jefferson Quesado
Friend, Before the Cout<<" n" put fflush(stdin);
– Anderson Henrique
nome
is the typechar
so your name can only be a letter. And in that sense the program is working well. If you want to read a name change to the typestring
making the corresponding include#include <cstring>
– Isac
Andersonhenrique I did here and it worked, in fact I didn’t even know what fflush(stdin) was, now I know, thanks. Isac I hadn’t noticed that either, I wanted to read a name myself, thanks for the tip.
– Pedro Afonso
Posso Colocar como Resposta então @Pedroafonso ?
– Anderson Henrique