Programming from a Flowchart

I need to do the following:

Write a complete C++ program given in the following flowchart. Test your program for temp = 80, 74, 55, and 102 and for zip = 43085, 38372, 43210, and 33040. Use the prinf function to display results.

I'm not sure how to paste the flowchart, but does anyone see anything apparently wrong with my program?

#include <iostream>
#include <math.h>
using namespace std;
int main(void) {
//Variable Declarations and Initializations
int k, t;
float max_temp, max_zip, zip, temp;
char msg1[80]="Welcome! This program computes the average high temperature of three locations";
//Assigment Statement
max_temp=0;
//Display of Header using formatted output
printf("%s\n", msg1);
//Initialize Conditions
{
for (k=0; k<=3; k=k+1)
//Get value of temp (high temperature)
cout << "Enter the high temperature: "; cin >> temp;
//Get value of zip (zip code)
cout << "Enter the zip code: "; cin >> zip;
}
//Print results for max_temp (maximum temperature) and max_zip (associated zip code)
if(temp>max_temp)
max_temp=temp;
max_zip=zip;
printf("Maximum temperature = %4d Associated zip code = %4d\n", max_temp, max_zip);
system("pause");
return 0;
}
Your brackets are wrong:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//You did this:
{
for(;;)
//Code
}

//Should be this:
for(;;)
{
//Code
}

//Also use them for if statements:
if(Condition)
{
//Code
}


You're also not using 't', and 'k' can be initialized in the for statement:
 
for(int k = 0;;) //Will initialize k to zero 


Also, your if(temp>max_temp) should be inside the for loop, because on every iteration you overwrite the last temp, so your program will always print the last temp that you input.

Why are you using C strings instead of the C++ string class? Is this a requirement?
System("pause") is usually looked down upon, due to its unportability and the amount of processing power it uses up. You could try something like std::getchar().
Topic archived. No new replies allowed.