ODDAVG - 编写一个程序来接受来自键盘的整数并找出10个奇数的平均值。如果输入的是偶数,则忽略计算中的数字,然后打印出“仅限奇数”的消息。我想要帮助此程序,我尝试了一个多小时?C++ odd平均值
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void Pause()
{ // function to freeze the screen, waiting for a `keypress`
string junk;
cout << "\n\n Press enter to continue...";
cin.ignore();
getline (cin,junk);
// void functions do not return a value
}
int main()
{
int even=0;
int odd=0;
int number=0;
int eventotal = 0;
int oddtotal = 0;
int counter = 0;
bool done;
int i;
// get `inpot`
cout << "Please enter 10 odd integers: " << endl << endl;
cin >> number;
cout << endl;
// display results
if ((number%2 == 0) && (number > 0))
{
cout << "odd numbers only please." << endl;
}
else if ((number > 0) && (i++))
{
odd++;
oddtotal = oddtotal +number;
}
while (number!=0)(!done);
counter ==10;
counter++;
int oddavg ;// to store the average of odd numbers
if(oddtotal!=0)
{
oddavg = oddtotal/ odd;
}
cout << " The average is: " << oddavg << endl;
// freeze screen
Pause();
return (0);
}
你已经明确地从某处复制过它。它甚至没有编译代码中的所有“'”。你试过什么了 ? – Arunmu
什么是'while(number!= 0)(!done);'应该这样做? –
把代码编译.. –