I am just trying to run this code from a book. I checked more than twice and still getting the two erros mentioned on the title. This code is intended to count how many times a value is repeated from input and if the last value entered is not the same as the previous one, it also has to start the count for this value.
#include <iostream>
int main()
{
int val=0, currVal=0;
if (std::cin>>currVal){
int cnt=1;
while (std::cin>>val){
(if val==currVal,++cnt)
else{
std::cout<<currVal<<"occurs"<<cnt<<"times"<<std::endl;
currVal=val;
cnt=1;}}
std::cout<<currVal<<"occurs"<<cnt<<"times"<<std::endl;}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire